fix(attrs): use base-10 only for int parsing (#373)#24
Conversation
…cion strconv.ParseInt with base 0 auto-detects hex (0x), octal (0o), and binary (0b) prefixes, causing attribute values like "0x0" and "0xFF" to silently parse as integers instead of remaining strings. Users passing hex strings as attribute values got unexpected type coercion. Fixes #373 🤖 Claude <claude@anthropic.com>
There was a problem hiding this comment.
Pull request overview
Updates attribute parsing so only base-10 integers are parsed, preventing 0x../0o..-prefixed values from being silently coerced into ints.
Changes:
- Switch
strconv.ParseIntfrom base0autodetect to base10only inStringMapAttrsToProtobuf - Add unit tests asserting
0x0,0xFF, and0o777stay as strings
Reviewed changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| otlpclient/protobuf_span.go | Forces integer parsing to base-10 to avoid coercing hex/octal-prefixed strings into ints |
| otlpclient/protobuf_span_test.go | Adds regression coverage for hex/octal-prefixed attribute values remaining strings |
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| "test 8 - hex string": "0x0", | ||
| "test 9 - hex string2": "0xFF", | ||
| "test 10 - octal str": "0o777", |
There was a problem hiding this comment.
The PR description mentions binary-prefixed strings (e.g., 0b1010) were also being parsed via base-0 autodetection, but the new tests only cover hex and octal. Add a test case asserting a 0b... value remains a string to fully cover the stated behavior.
| "test 9 - hex string2": "0xFF", | ||
| "test 10 - octal str": "0o777", |
There was a problem hiding this comment.
Test case names like "hex string2" and "octal str" are a bit unclear/inconsistent. Consider renaming to something more descriptive and consistent (e.g., "hex string - uppercase" / "octal-prefixed string"), since these names show up in failures and help quickly identify intent.
Summary
0x0,0xFF, and0o777were silently parsed as integers due tostrconv.ParseIntwith base 0 auto-detecting hex/octal/binary prefixesTest plan
otlpclient/protobuf_span_test.gofor0x0,0xFF,0o777go test && go test ./...)Fixes #373
🤖 Generated with Claude Code