Skip to content

fix: return undefined from getPrefix/parseId for non-string input - #13

Open
shaurya703 wants to merge 1 commit into
suhailopensource:mainfrom
shaurya703:fix/non-string-input
Open

fix: return undefined from getPrefix/parseId for non-string input#13
shaurya703 wants to merge 1 commit into
suhailopensource:mainfrom
shaurya703:fix/non-string-input

Conversation

@shaurya703

Copy link
Copy Markdown
Contributor

getPrefix() and parseId() crashed with TypeError: Cannot read properties of null (reading 'indexOf') when handed non-string input, while isId() and getTimestamp() already tolerated it. This made half the read-side API unsafe for untrusted values from request bodies, query strings, and databases — especially in plain JavaScript where there is no compiler to catch the mismatch.

Changes

  • Added a typeof value !== "string" guard returning undefined at the top of both getPrefix and parseId in src/utils/validate.ts, matching the existing isId / getTimestamp behaviour.
  • Added tests to test/validate.test.ts covering null, undefined, numbers, and objects for both functions.
  • CHANGELOG entry under Unreleased.

Verification

npm run format, npm run typecheck, npm test (108 passing), npm run build, and npm run smoke all pass.

Fixes #10

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.

[bug] : getPrefix() / parseId() throw on non-string input

1 participant