{{ message }}
fix(shared): only treat whole-string status codes as reserved usernames - #69853
Open
rajanpanth wants to merge 1 commit into
Open
fix(shared): only treat whole-string status codes as reserved usernames#69853rajanpanth wants to merge 1 commit into
rajanpanth wants to merge 1 commit into
Conversation
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.
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.

Checklist:
mainbranch of freeCodeCamp.What
isHttpStatusCodeinpackages/shared/src/utils/validate.tsusesparseInt, 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:The sibling test states the intent: "rejects strings which are http response status codes 100-599".
500pxis 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 assertingUsername 404 is a reserved error codeis unaffected, and0500(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 andtsc --noEmitare clean on the changed files.