Skip to content

Commit

Permalink
better round trip for dots
Browse files Browse the repository at this point in the history
  • Loading branch information
ywwg committed Nov 22, 2024
1 parent f49981c commit 2767f76
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 7 deletions.
2 changes: 1 addition & 1 deletion model/metric.go
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,7 @@ func EscapeName(name string, scheme EscapingScheme) string {
} else if isValidLegacyRune(b, i) {
escaped.WriteRune(b)
} else {
escaped.WriteRune('_')
escaped.WriteString("__")
}
}
return escaped.String()
Expand Down
12 changes: 6 additions & 6 deletions model/metric_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -281,26 +281,26 @@ func TestEscapeName(t *testing.T) {
name: "name with spaces and emoji",
input: "label with 😱",
expectedUnderscores: "label_with__",
expectedDots: "label_with__",
expectedUnescapedDots: "label_with_",
expectedDots: "label__with____",
expectedUnescapedDots: "label_with__",
expectedValue: "U__label_20_with_20__1f631_",
},
{
name: "name with unicode characters > 0x100",
input: "花火",
expectedUnderscores: "__",
expectedDots: "__",
expectedDots: "____",
// Dots-replacement does not know the difference between two replaced
// characters and a single underscore.
expectedUnescapedDots: "_",
expectedUnescapedDots: "__",
expectedValue: "U___82b1__706b_",
},
{
name: "name with spaces and edge-case value",
input: "label with \u0100",
expectedUnderscores: "label_with__",
expectedDots: "label_with__",
expectedUnescapedDots: "label_with_",
expectedDots: "label__with____",
expectedUnescapedDots: "label_with__",
expectedValue: "U__label_20_with_20__100_",
},
}
Expand Down

0 comments on commit 2767f76

Please sign in to comment.