opentelemetry-go icon indicating copy to clipboard operation
opentelemetry-go copied to clipboard

Baggage propagation - replace invalid percent-encoded octet sequnces with replacement char

Open lachmatt opened this issue 1 year ago • 3 comments

W3C baggage spec requires:

When decoding the value, percent-encoded octet sequences that do not match the UTF-8 encoding scheme MUST be replaced with the replacement code point (U+FFFD).

This situation is currently not handled correctly - see playground for sample:

package main

import (
	"fmt"
	"log"
	"unicode/utf8"

	"go.opentelemetry.io/otel/baggage"
)

func main() {
	kv := "k=aa%ffcc"

	b, err := baggage.Parse(kv)
	if err != nil {
		log.Fatal(err)
	}
	val := b.Members()[0].Value()

	fmt.Println(val)
	fmt.Println(len(val))
	fmt.Println(utf8.ValidString(val))

	validStringWithReplacements := "aa�cc"
	fmt.Println(len(validStringWithReplacements))
	fmt.Println(utf8.ValidString(validStringWithReplacements))
}

lachmatt avatar Jun 18 '24 14:06 lachmatt

hey @lachmatt what is the expected behavior?

that code should return 7 and true, right?

fmt.Println(len(val))
fmt.Println(utf8.ValidString(val))

santileira avatar Jun 19 '24 16:06 santileira

that code should return 7 and true

This is correct.

From https://www.compart.com/en/unicode/U+FFFD:

UTF-8 Encoding: 0xEF 0xBF 0xBD

pellared avatar Jun 19 '24 18:06 pellared

@pellared I could fix it, could you assign me this issue?

santileira avatar Jun 19 '24 19:06 santileira

@pellared / @dmathieu We already merged the code to solve this issue, should we close the issue? Thanks

santileira avatar Jul 08 '24 13:07 santileira

Fixed in https://github.com/open-telemetry/opentelemetry-go/pull/5528.

dmathieu avatar Jul 08 '24 13:07 dmathieu