refactor(backend): reuse Stellar public key regex - #1348
Merged
K1NGD4VID merged 1 commit intoAug 30, 2026
Conversation
The user controller redeclared the Stellar public key pattern
/^G[A-Z2-7]{55}$/ inline at three validation sites, duplicating
STELLAR_PUBLIC_KEY_REGEX already exported from
backend/src/validators/user.validator.ts. Import the shared constant
and use it in getUser, getUserEvents and exportTransactions so the
format check has a single definition. Validation behaviour is
unchanged: the pattern is identical and carries no global flag, so
.test() stays stateless across calls.
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Closes #1272
Summary
backend/src/controllers/user.controller.tsredeclared the Stellar public key pattern/^G[A-Z2-7]{55}$/inline instead of usingSTELLAR_PUBLIC_KEY_REGEX, which is already exported frombackend/src/validators/user.validator.ts:11.This PR imports the shared constant and uses it at every Stellar-address format check in the controller. The audit named two sites; a third had since appeared in
exportTransactions, so all three are covered and no inline Stellar-address literal remains in the controller.Behaviour is unchanged. The pattern is byte-for-byte the same, and the shared
RegExpcarries nog/yflag, solastIndexis never advanced and.test()stays stateless across calls.Files changed
backend/src/controllers/user.controller.tsSTELLAR_PUBLIC_KEY_REGEXto the existing import from../validators/user.validator.jsgetUser(line 109): inline regex ->STELLAR_PUBLIC_KEY_REGEX.test(publicKey)getUserEvents(line 143): inline regex ->STELLAR_PUBLIC_KEY_REGEX.test(publicKey)exportTransactions(line 257): inline regex ->STELLAR_PUBLIC_KEY_REGEX.test(address)No new constant was introduced, the regex itself was not touched, and no other controller code was refactored.
Tests run and actual results
All commands run from
backend/:Existing
tests/user.controller.test.tsalready asserts the 400 responses for malformed public keys onGET /users/:publicKeyandGET /users/:publicKey/events, andtests/user.validator.test.tscovers the shared regex, so no new test was added for a like-for-like constant substitution.Note: running a vitest subset trips the repo's global 60% coverage threshold, which is a property of the subset, not a failure of these tests. Coverage was disabled for the runs above; the full unit suite passes as reported.
Verification
Acceptance criteria
STELLAR_PUBLIC_KEY_REGEXis imported from the existing validator modulenpm run build)Out of scope
frontend/src/lib/stellar.ts:8andfrontend/src/lib/csv-parser.ts:47also carry the same literal, but they live in a separate workspace that cannot import the backend validator. Left untouched to keep this PR scoped to #1272.🤖 Generated with Claude Code