test(sanitize): add regression suite for getByPath nullish traversal and boundary contracts - #1238
Open
eteonninob-arch wants to merge 1 commit into
Conversation
…and boundary contracts
|
@eteonninob-arch Great news! 🎉 Based on an automated assessment of this PR, the linked Wave issue(s) no longer count against your application limits. You can now already apply to more issues while waiting for a review of this PR. Keep up the great work! 🚀 |
eteonninob-arch
force-pushed
the
test/sanitize-options-regression-suite
branch
from
September 29, 2026 21:44
2f57b95 to
42646f4
Compare
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 #1045
Hardens and exercises the path-traversal failure and empty-result branch in
src/lib/sanitize.ts:171(if (cur == null) return undefined;). Adds comprehensive NatSpec/JSDoc documentation togetByPathandsetByPath, exports both helper methods without modifying existing public contracts, and establishes an exhaustive regression test suite insrc/lib/sanitize.test.tsachieving 100% statement, branch, function, and line coverage.Problem & Evidence
src/lib/sanitize.ts:171containsif (cur == null) return undefined;insidegetByPath.'user.profile.bio'), intermediate nullish properties (nullorundefined) short-circuit traversal and returnundefined. Prior to this change, this empty-result / failure path lacked deterministic boundary tests and explicit contract assertions, leaving the codebase susceptible to silent regressions during path resolution or object sanitation.Solution & Key Changes
Contract Hardening & Documentation (
src/lib/sanitize.ts):undefined) vs terminal leaf null values (null).getByPathandsetByPathfor direct observability and unit verification while fully preserving the existing module contract for all consumers ofsanitizeObjectandsanitizeString.no-control-regexand explicitanytags).Deterministic Regression Suite (
src/lib/sanitize.test.ts):if (cur == null) return undefined;):null:{ user: null }with path'user.profile'->undefined.undefined:{ user: undefined }with path'user.profile'->undefined.null:{ a: { b: { c: null } } }with path'a.b.c.d.e'->undefined.undefined:{ a: { b: { c: undefined } } }with path'a.b.c.d'->undefined.{ a: {} }with path'a.b.c'->undefined.{ a: 42 },{ a: false }, and{ a: 'scalar' }with path'a.b.c'->undefined.getByPath(null, 'a.b')andgetByPath(undefined, 'a.b')->undefined.nullcontract distinction: verifies that{ a: { b: null } }with path'a.b'preserves explicitnull, while'a.b.c'yieldsundefined."", consecutive dots'a..b', leading dots'.a', and trailing dots'a.'.setByPathContainer Creation & Mutation Safeguards:nullor primitive scalars (typeof cur[p] !== 'object') with clean object containers ({}).sanitizeObjectIntegration Tests:nullwith optional rule -> preserved asnullwithout mutation.nullwith required and default rule -> reparented to object container with sanitized fallback.undefinedwith required and default rule -> populated with sanitized nested default.type: 'string[]'vs non-array inputs.Validation & Test Results
src/lib/sanitize.test.ts):src/middleware/offeringSanitize.test.ts):tsc --noEmit src/lib/sanitize.ts src/lib/sanitize.test.ts-> 0 errorseslint src/lib/sanitize.ts src/lib/sanitize.test.ts-> 0 errors, 0 warnings