-
-
Notifications
You must be signed in to change notification settings - Fork 16
Add plenty of unit tests to address more code coverage gaps #2711
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -460,10 +460,8 @@ class JSONPathParser { | |||||||||||
| // member-name-shorthand = name-first *name-char | ||||||||||||
| auto parse_shorthand_name() -> JSONPath::SelectorName { | ||||||||||||
| JSON::String name; | ||||||||||||
| if (this->at_end()) { | ||||||||||||
| this->fail(); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // Every caller rejects a query that ends right before a shorthand name | ||||||||||||
| assert(!this->at_end()); | ||||||||||||
| const auto first{static_cast<unsigned char>(this->peek())}; | ||||||||||||
| if (first == '_' || is_alpha(static_cast<char>(first))) { | ||||||||||||
| name += static_cast<char>(first); | ||||||||||||
|
|
@@ -641,36 +639,33 @@ class JSONPathParser { | |||||||||||
| } | ||||||||||||
|
|
||||||||||||
| // comparison-op = "==" / "!=" / "<=" / ">=" / "<" / ">" | ||||||||||||
| // Callers look ahead for a full comparison operator before parsing one, so | ||||||||||||
| // the first character is one of the four operator openers, and an equals | ||||||||||||
| // sign always follows an exclamation mark or another equals sign | ||||||||||||
| auto parse_comparison_operator() -> JSONPath::FilterComparisonOperator { | ||||||||||||
| const char character{this->peek()}; | ||||||||||||
| if (character == '=' || character == '!') { | ||||||||||||
| this->position_ += 1; | ||||||||||||
| if (this->at_end() || this->peek() != '=') { | ||||||||||||
| this->fail(); | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| assert(!this->at_end() && this->peek() == '='); | ||||||||||||
|
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. P3: This refactor replaces the defensive Prompt for AI agents
Suggested change
|
||||||||||||
| this->position_ += 1; | ||||||||||||
| return character == '=' ? JSONPath::FilterComparisonOperator::Equal | ||||||||||||
| : JSONPath::FilterComparisonOperator::NotEqual; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (character == '<' || character == '>') { | ||||||||||||
| assert(character == '<' || character == '>'); | ||||||||||||
| this->position_ += 1; | ||||||||||||
| const bool inclusive{!this->at_end() && this->peek() == '='}; | ||||||||||||
| if (inclusive) { | ||||||||||||
| this->position_ += 1; | ||||||||||||
| const bool inclusive{!this->at_end() && this->peek() == '='}; | ||||||||||||
| if (inclusive) { | ||||||||||||
| this->position_ += 1; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| if (character == '<') { | ||||||||||||
| return inclusive ? JSONPath::FilterComparisonOperator::LessEqual | ||||||||||||
| : JSONPath::FilterComparisonOperator::Less; | ||||||||||||
| } | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| return inclusive ? JSONPath::FilterComparisonOperator::GreaterEqual | ||||||||||||
| : JSONPath::FilterComparisonOperator::Greater; | ||||||||||||
| if (character == '<') { | ||||||||||||
| return inclusive ? JSONPath::FilterComparisonOperator::LessEqual | ||||||||||||
| : JSONPath::FilterComparisonOperator::Less; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| this->fail(); | ||||||||||||
| return inclusive ? JSONPath::FilterComparisonOperator::GreaterEqual | ||||||||||||
| : JSONPath::FilterComparisonOperator::Greater; | ||||||||||||
| } | ||||||||||||
|
|
||||||||||||
| auto parse_comparison_or_test() -> JSONPath::FilterExpression { | ||||||||||||
|
|
||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
P2: Converting the out-of-range length check to
assertremoves the safety net in release builds:assertis compiled out underNDEBUG, so if any caller ever passes a length greater than MAX_HUFFMAN_BITS (15),count_[lengths[symbol]]becomes an out-of-bounds write into the 16-elementcount_array instead of throwing a cleanGZIPErroras before. The current gzip callers do guarantee lengths ≤ 15, andHuffmanDecoder::buildis a public method of this library header, so this is a latent robustness regression. Consider keeping the runtime validation (throw) so malformed or unexpected lengths are handled gracefully even in optimized builds, or document that the method now requires lengths ≤ MAX_HUFFMAN_BITS from all future callers.Prompt for AI agents