[Access] Fix ParseAddress() by only removing prefix "0x"#8453
[Access] Fix ParseAddress() by only removing prefix "0x"#8453
ParseAddress() by only removing prefix "0x"#8453Conversation
Currently, ParseAddress() removes all instances of "0x" in the address input, instead of just the "0x" prefix. This bug can cause an invalid input address containing a non-prefix "0x" to be treated as valid. This commit: - only removes "0x" only if it is a prefix - returns an error if "0x" is present as a non-prefix - adds a test case for this
Dependency Review✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.Scanned FilesNone |
📝 WalkthroughWalkthroughThe address parser normalization is refined to remove only the leading "0x" prefix instead of stripping all occurrences throughout the string. A test case for double-prefixed malformed addresses is added to verify rejection as invalid. Changes
Estimated code review effort🎯 2 (Simple) | ⏱️ ~8 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing Touches
🧪 Generate unit tests (beta)
Tip Issue Planner is now in beta. Read the docs and try it out! Share your feedback on Discord. Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
There was a problem hiding this comment.
🧹 Nitpick comments (1)
engine/access/rest/common/parser/address_test.go (1)
58-58: Consider aligning the assertion helper withstrings.TrimPrefix.Line 58 still uses
strings.ReplaceAll(input, "0x", "")to compute the expected address string. While functionally equivalent for the current valid inputs (valid hex strings can never contain"x", soReplaceAllandTrimPrefixalways yield the same result), it is now semantically out of sync with howParseAddressactually normalises the input.♻️ Suggested update for conceptual alignment
- assert.Equal(t, strings.ReplaceAll(input, "0x", ""), address.String()) + assert.Equal(t, strings.TrimPrefix(input, "0x"), address.String())🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed. In `@engine/access/rest/common/parser/address_test.go` at line 58, Update the test assertion to use strings.TrimPrefix to compute the expected normalized address instead of strings.ReplaceAll; specifically, change the assertion that compares address.String() (the line using assert.Equal and strings.ReplaceAll(input, "0x", "")) to use strings.TrimPrefix(input, "0x") so the test semantics match how ParseAddress normalizes inputs.
🤖 Prompt for all review comments with AI agents
Verify each finding against the current code and only fix it if needed.
Nitpick comments:
In `@engine/access/rest/common/parser/address_test.go`:
- Line 58: Update the test assertion to use strings.TrimPrefix to compute the
expected normalized address instead of strings.ReplaceAll; specifically, change
the assertion that compares address.String() (the line using assert.Equal and
strings.ReplaceAll(input, "0x", "")) to use strings.TrimPrefix(input, "0x") so
the test semantics match how ParseAddress normalizes inputs.
ℹ️ Review info
Configuration used: defaults
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (2)
engine/access/rest/common/parser/address.goengine/access/rest/common/parser/address_test.go
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
Currently,
ParseAddress()removes all instances of "0x" in the address input, instead of just the "0x" prefix.This bug can cause an invalid input address containing a non-prefix "0x" to be treated as valid.
This PR:
Summary by CodeRabbit