Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: values escaping bugs #727

Merged
merged 1 commit into from
Nov 27, 2024
Merged

fix: values escaping bugs #727

merged 1 commit into from
Nov 27, 2024

Conversation

ywwg
Copy link
Member

@ywwg ywwg commented Nov 21, 2024

I missed some test cases the first time around. Confirmed that without this fix the test cases fail the round trip.

@ywwg ywwg marked this pull request as draft November 21, 2024 17:49
@ywwg ywwg marked this pull request as ready for review November 21, 2024 18:11
@ywwg ywwg changed the title fix: values escaping needs to double underscores fix: values escaping bugs Nov 21, 2024
@ywwg ywwg requested a review from beorn7 November 21, 2024 18:36
Copy link
Member

@jesusvazquez jesusvazquez left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've had a look and since tests are working It gives us some assurances.

Left a couple questions for my own understanding.

model/metric.go Outdated
@@ -391,7 +382,7 @@ func UnescapeName(name string, scheme EscapingScheme) string {
var utf8Val uint
for j := 0; i < len(escapedName); j++ {
// This is too many characters for a utf8 value.
if j > 4 {
if j > 8 {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Where does this come from?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

the max UTF codepoint is '\U0010FFFF', therefore the max number of characters is actually 6, not 8.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry I dived a bit and found a few constants, have a look at this https://go.dev/play/p/PoHxOOeoyQu

The maximum number of bytes needed to represent unicode.MaxRune is: 4
There is also utf8.UTFMAX: : 4

Shouldnt this remain as 4?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Wait, it should be 7, right? The 4 bytes in the longest possible rune encode as 8 hexadecimal digits, so j can legally be between 0 and 7.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

ah yup, 7 is correct

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

well, maxrune is \U0010FFFF so maybe 6 is too many characters?

Copy link
Member

@beorn7 beorn7 Nov 27, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry for slow thinking. I think I got it now:

utf8.UTFMAX is about the bytes needed in UTF-8 encoded form. But what we put into the U__ encoding is the code point, which is different from the encoded byte sequence. The codepoint \U0010FFFF that @ywwg mentioned would be written as U___10FFFF_. As UTF-8 string, it would take the byte pattern F4 8F BF BF (the 4 bytes max length that utf8.UTFMAX refers to).

But this means the correct number here is 5, don't you think so?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

aha yes -- or as you suggest, >=6

@@ -318,21 +315,15 @@ func EscapeName(name string, scheme EscapingScheme) string {
}
escaped.WriteString("U__")
for i, b := range name {
if isValidLegacyRune(b, i) {
if b == '_' {
escaped.WriteString("__")
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Something rings a bell that this was decided when there is an underscore put two underscores but could we add a reference to where this was agreed on?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is necessary so that we can know to start parsing a unicode value if we see only 1 underscore. this is similar to dots escaping where dots become _dot_ and we double underscores.

model/metric_test.go Outdated Show resolved Hide resolved
Issues with underscores and large unicode value conversion

Signed-off-by: Owen Williams <[email protected]>
@ywwg ywwg merged commit 39a62f7 into main Nov 27, 2024
8 checks passed
@ywwg ywwg deleted the owilliams/underscores branch November 27, 2024 18:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants