fix(p2-json-errors): remove safe-but-flagged unwrap in is_type_id_value#82
Merged
Merged
Conversation
The `.unwrap()` on `trimmed.chars().next()` was provably safe given the prior `is_empty()` guard, but the `code-unwrap` audit pattern-matches on `.unwrap()` call expressions and reported it on self-dogfood. Replace with a `let-else` returning `false` (the function's canonical invalid-input response). One line of substance plus a comprehensive unit test covering Number/Bool/Null/Array/Object/string-shape variants. Surfaced during PR #80 review.
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.
Summary
Addresses the
json_errors.rs:192finding from PR #80's dogfood run: the.unwrap()ontrimmed.chars().next()insideis_type_id_valuewas provably safe (anis_empty()guard ten lines earlier guarantees at least one char), but thecode-unwrapsource audit pattern-matches on.unwrap()call expressions and surfaced it during self-dogfood.Replaces the
.unwrap()with alet-elsethat returnsfalse, consistent with the function's "return false on any invalid input" pattern. Adds a comprehensive unit test (is_type_id_value_validates_json_shapes) covering all five non-string JSON value kinds (Number, Bool, Null, Array, Object), three valid identifier shapes (kebab-case, SCREAMING_SNAKE, snake_case), and three invalid string shapes (whitespace, period-separated, leading digit).Changelog
Fixed
code-unwrapself-dogfood finding atjson_errors.rs:192: replace.unwrap()with alet-elsereturningfalseinis_type_id_value.Type of Change
fix: Bug fix (non-breaking change which fixes an issue)Related Issues/Stories
json_errors.rs:192as the one remainingcode-unwrapfinding)code-unwrapaudit).unwrap()that this PR removes)Testing
Test Summary:
cargo test: 848 passed, 2 ignored (8 suites). +1 new testis_type_id_value_validates_json_shapesinsrc/audits/behavioral/json_errors.rs.cargo clippy --all-targets -- -Dwarnings: clean.cargo fmt --check: clean.Files Modified
Modified:
src/audits/behavioral/json_errors.rs: replace.unwrap()withlet-elseat line 192; addis_type_id_value_validates_json_shapesunit test.Created:
Renamed:
Deleted:
Breaking Changes
Deployment Notes
Checklist