Skip to content

Commit b9b5aa5

Browse files
datadog: sanitize characters in Latin-1 supplement
Add test cases to reproduce the panic, and then fix the panic.
1 parent 007b723 commit b9b5aa5

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

datadog/serializer.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ func (s *serializer) AppendMeasures(b []byte, _ time.Time, measures ...stats.Mea
8787
var accentMap [256]byte
8888

8989
// valid[byte] = 1 if the ASCII char is allowed, 0 otherwise.
90-
var valid = [128]bool{
90+
var valid = [256]bool{
9191
'.': true, '-': true, '_': true,
9292
}
9393

datadog/serializer_test.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -298,6 +298,12 @@ func TestAppendSanitizedMetricName(t *testing.T) {
298298
{"", "naïve🌍test", "naive_test"}, // ï -> i, emoji -> _
299299
{"", "umlauts.🤡München", "umlauts._Munchen"}, // emoji + German umlauts
300300

301+
// Unmapped Latin-1 Supplement characters (regression test for panic)
302+
{"", "test÷metric", "test_metric"}, // ÷ (division sign, U+00F7, byte 247)
303+
{"", "value×count", "value_count"}, // × (multiplication sign, U+00D7, byte 215)
304+
{"", "price¤amount", "price_amount"}, // ¤ (currency sign, U+00A4)
305+
{"prefix_", "data÷by×time", "prefix_data_by_time"}, // multiple unmapped chars with prefix
306+
301307
// empty or only illegal
302308
{"", "", "_unnamed_"},
303309
{"", "!!!", "_truncated_"},

0 commit comments

Comments
 (0)