fix(shared): only treat whole-string status codes as reserved usernames by rajanpanth · Pull Request #69853 · freeCodeCamp/freeCodeCamp · GitHub
Skip to content

fix(shared): only treat whole-string status codes as reserved usernames - #69853

Open
rajanpanth wants to merge 1 commit into
freeCodeCamp:mainfrom
rajanpanth:fix/username-status-code-prefix
Open

fix(shared): only treat whole-string status codes as reserved usernames#69853
rajanpanth wants to merge 1 commit into
freeCodeCamp:mainfrom
rajanpanth:fix/username-status-code-prefix

Conversation

@rajanpanth

Copy link
Copy Markdown
Contributor

Checklist:

What

isHttpStatusCode in packages/shared/src/utils/validate.ts uses parseInt, which stops at the first non-digit. Any username that merely starts with a 100-599 prefix is therefore rejected with a factually wrong message:

"500px"        -> Username "500px" is a reserved error code
"404notfound"  -> Username "404notfound" is a reserved error code
"200ok"        -> Username "200ok" is a reserved error code
"789"          -> valid (789 is not a status code, correct)

The sibling test states the intent: "rejects strings which are http response status codes 100-599". 500px is not a status code.

Changes

An anchored regex, /^[1-5][0-9]{2}$/, so the whole string must be a status code. Every real status code stays reserved: the existing api test asserting Username 404 is a reserved error code is unaffected, and 0500 (no longer a parseable "500") is now accepted, matching the function's name and documented range.

Verification

A regression test is added ("accepts strings which merely start with a status code"). Reverting only the source while keeping the test fails it with {"error": "is a reserved error code", "valid": false}; restoring passes the full shared validate suite (55 tests). Prettier and tsc --noEmit are clean on the changed files.

isHttpStatusCode used parseInt, which stops at the first non-digit, so any
username merely starting with 100-599 was rejected: '500px', '404notfound'
and '200ok' all produced 'Username ... is a reserved error code'. The
sibling test states the intent as rejecting strings which ARE status codes.

An anchored /^[1-5][0-9]{2}$/ keeps every real status code reserved (the
existing '404' test still passes) while allowing usernames that only start
with one.
@rajanpanth
rajanpanth requested review from a team as code owners September 3, 2026 00:50
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant