Skip to content

[Access] Fix ParseAddress() by only removing prefix "0x"#8453

Merged
fxamacker merged 1 commit intomasterfrom
fxamacker/fix-parse-address-bug
Feb 23, 2026
Merged

[Access] Fix ParseAddress() by only removing prefix "0x"#8453
fxamacker merged 1 commit intomasterfrom
fxamacker/fix-parse-address-bug

Conversation

@fxamacker
Copy link
Copy Markdown
Contributor

@fxamacker fxamacker commented Feb 23, 2026

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:

  • 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

Summary by CodeRabbit

  • Bug Fixes
    • Improved address parsing normalization to remove only a single leading "0x" prefix instead of stripping all occurrences. This ensures more robust handling of address inputs with unusual formatting and enhances validation accuracy.

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
@fxamacker fxamacker requested a review from peterargue February 23, 2026 16:56
@fxamacker fxamacker self-assigned this Feb 23, 2026
@fxamacker fxamacker requested a review from a team as a code owner February 23, 2026 16:56
@github-actions
Copy link
Copy Markdown
Contributor

Dependency Review

✅ No vulnerabilities or license issues or OpenSSF Scorecard issues found.

Scanned Files

None

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai bot commented Feb 23, 2026

📝 Walkthrough

Walkthrough

The 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

Cohort / File(s) Summary
Address Parser Update
engine/access/rest/common/parser/address.go, engine/access/rest/common/parser/address_test.go
Modified prefix removal logic from ReplaceAll (all occurrences) to TrimPrefix (leading only); test case added for malformed input with double "0x" prefix validation.

Estimated code review effort

🎯 2 (Simple) | ⏱️ ~8 minutes

Possibly related PRs

Suggested reviewers

  • janezpodhostnik

Poem

🐰 A pair of oh-exes causing trouble,
We stripped them all—a parsing bubble,
Now just the leading one must go,
The address parser passes the test show! ✨

🚥 Pre-merge checks | ✅ 2 | ❌ 1

❌ Failed checks (1 warning)

Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. Write docstrings for the functions missing them to satisfy the coverage threshold.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title clearly and concisely summarizes the main change: fixing ParseAddress() to remove only a leading '0x' prefix instead of all occurrences.

✏️ Tip: You can configure your own custom pre-merge checks in the settings.

✨ Finishing Touches
  • 📝 Generate docstrings (stacked PR)
  • 📝 Generate docstrings (commit on current branch)
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch fxamacker/fix-parse-address-bug

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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai bot left a comment

Choose a reason for hiding this comment

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

🧹 Nitpick comments (1)
engine/access/rest/common/parser/address_test.go (1)

58-58: Consider aligning the assertion helper with strings.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", so ReplaceAll and TrimPrefix always yield the same result), it is now semantically out of sync with how ParseAddress actually 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

📥 Commits

Reviewing files that changed from the base of the PR and between 4f88a2a and 010fa93.

📒 Files selected for processing (2)
  • engine/access/rest/common/parser/address.go
  • engine/access/rest/common/parser/address_test.go

@fxamacker fxamacker requested review from a team and zhangchiqing February 23, 2026 17:27
@fxamacker fxamacker added this pull request to the merge queue Feb 23, 2026
Merged via the queue into master with commit d9df449 Feb 23, 2026
61 checks passed
@fxamacker fxamacker deleted the fxamacker/fix-parse-address-bug branch February 23, 2026 17:55
@codecov-commenter
Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants