Skip to content

Bug: TokenSelector.tsx's Stellar address regex accepts invalid characters, and the component has zero test coverage #224

Description

@Jaydbrown

Location

components/TokenSelector.tsx:35 (regex); component-wide (test coverage)

Description

Two related gaps in the same file:

  1. The address-validation regex /^[GC][A-Z0-9]{55}$/ accepts characters (0, 1, 8, 9) that can never appear in a valid Stellar StrKey address (base32, RFC4648 alphabet A-Z2-7), deferring the real error to a much worse network-level failure message. It also accepts a G-prefixed (account) address for a field that, per its purpose (selecting a token contract), should only accept C-prefixed (contract) addresses.
  2. This component has real async data-fetching, abort-handling, and error-branching logic, but no corresponding test file at all, unlike most comparable components in components/stream/.

Why it matters

Users get a confusing late-stage RPC error instead of immediate client-side validation feedback, and could paste an account address into a token-contract field with no warning. The complete lack of tests is exactly why this regex bug went unnoticed.

Suggested fix

Fix the regex to /^C[A-Z2-7]{55}$/ (contract addresses only, correct alphabet), or use the Stellar SDK's own StrKey validation helpers. Add components/TokenSelector.test.tsx covering valid/invalid address input, loading state, abort/cancellation on rapid re-selection, error display, and a regression test for this exact regex bug.

Acceptance criteria

  • Regex only accepts the valid base32 alphabet, scoped to contract (C...) addresses
  • TokenSelector.test.tsx exists with meaningful coverage of the async/validation/error paths, including a regression test for the regex fix

Metadata

Metadata

Assignees

Labels

Stellar WaveIssues in the Stellar wave programbugSomething isn't workingenhancementNew feature or request

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions