-
-
Notifications
You must be signed in to change notification settings - Fork 0
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
✨ DecodeOptions.strict_depth option to throw when input is beyond depth #8
Conversation
WalkthroughThe recent updates to the Changes
Sequence Diagram(s)sequenceDiagram
participant User
participant DecodeOptions
participant Decode
participant Parser
User->>DecodeOptions: Set strict_depth = True
User->>Decode: Call decode(input, options)
Decode->>Parser: Parse the input with options
alt Depth exceeds limit
Parser-->>Decode: Raise IndexError
Decode-->>User: Return error message
else Depth within limit
Parser-->>Decode: Return decoded data
Decode-->>User: Provide decoded output
end
Poem
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
Coverage summary from CodacySee diff coverage on Codacy
Coverage variation details
Coverage variation is the difference between the coverage for the head and common ancestor commits of the pull request branch: Diff coverage details
Diff coverage is the percentage of lines that are covered by tests out of the coverable lines that the pull request added or modified: See your quality gate settings Change summary preferencesCodacy stopped sending the deprecated coverage status on June 5th, 2024. Learn more |
Codecov ReportAll modified and coverable lines are covered by tests ✅
Additional details and impacted files@@ Coverage Diff @@
## main #8 +/- ##
==========================================
+ Coverage 96.75% 96.77% +0.01%
==========================================
Files 16 16
Lines 709 713 +4
==========================================
+ Hits 686 690 +4
Misses 23 23 ☔ View full report in Codecov by Sentry. |
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.
Actionable comments posted: 0
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (5)
- README.rst (1 hunks)
- docs/README.rst (1 hunks)
- src/qs_codec/decode.py (1 hunks)
- src/qs_codec/models/decode_options.py (1 hunks)
- tests/unit/decode_test.py (1 hunks)
Additional comments not posted (13)
src/qs_codec/models/decode_options.py (1)
80-81
: LGTM! Thestrict_depth
attribute is well-documented.The addition of the
strict_depth
attribute is clear and enhances the class functionality by providing an option for stricter input depth handling.src/qs_codec/decode.py (1)
197-198
: LGTM! Verify the usage ofstrict_depth
.The addition of the
strict_depth
check in_parse_keys
enhances error handling by enforcing depth limits. Ensure that this change is appropriately integrated and tested across the codebase.To verify the integration, check for tests or usages that involve
strict_depth
.Verification successful
strict_depth
is well-integrated and tested.The
strict_depth
option is thoroughly tested intests/unit/decode_test.py
, covering various scenarios to ensure its correct functionality. This confirms that the feature is appropriately integrated across the codebase.Scripts executed
The following scripts were executed for the analysis:
Script:
#!/bin/bash # Description: Verify the usage of `strict_depth` in tests or other parts of the codebase. # Test: Search for `strict_depth` usage in the repository. Expect: Occurrences in test files or relevant code sections. rg --type py 'strict_depth'Length of output: 2229
docs/README.rst (1)
71-88
: LGTM! The documentation forstrict_depth
is comprehensive and clear.The documentation effectively explains the new
strict_depth
feature and provides useful examples for users. This addition enhances the usability and understanding of the decoding options.tests/unit/decode_test.py (9)
648-650
: Correctly tests IndexError for nested objects with strict depth.The test verifies that an
IndexError
is raised when the input exceeds the specified depth withstrict_depth
enabled.
652-654
: Correctly tests IndexError for nested lists with strict depth.This test ensures that the
decode
function raises anIndexError
for deeply nested lists whenstrict_depth
is set toTrue
.
656-658
: Correctly tests IndexError for mixed nested structures with strict depth.The test checks that an
IndexError
is raised for a combination of nested dictionaries and lists whenstrict_depth
is enabled.
660-662
: Correctly tests IndexError for various value types with strict depth.This test ensures that different types of values in nested structures trigger an
IndexError
whenstrict_depth
isTrue
.
664-666
: Correctly handles depth of 0 with strict depth true.The test confirms that no exception is thrown when the depth is set to
0
andstrict_depth
isTrue
, maintaining compatibility.
668-669
: Correctly decodes within depth limit with strict depth.This test verifies successful decoding when the input depth is within the specified limit with
strict_depth
enabled.
671-674
: Correctly handles exceeding depth with strict depth false.The test confirms that no exception is raised when the depth exceeds the limit if
strict_depth
isFalse
, and the input is decoded as expected.
676-677
: Correctly decodes within depth limit with strict depth false.This test ensures that decoding succeeds when the depth is within the limit and
strict_depth
isFalse
.
679-680
: Correctly handles exact depth limit with strict depth true.The test verifies that no exception is thrown when the input depth is exactly at the limit with
strict_depth
enabled.README.rst (1)
96-113
: Clear explanation of strict_depth feature.The documentation clearly explains the purpose and usage of the
strict_depth
option, including how it enhances security by enforcing depth limits.
Description
This PR adds
DecodeOptions.strict_depth
to enforce throwing when input depth is beyond the depth option.Defaults to
false
.Throws
RangeError
.If depth has been set by the user to
0
, we do not throw, but fallback to the previous behaviour.Type of change
How Has This Been Tested?
Added additional tests
Checklist:
Ref ljharb/qs#511
Summary by CodeRabbit
New Features
strict_depth
option allowing users to configure depth limits during decoding.Bug Fixes
IndexError
when depth exceeds limits withstrict_depth
enabled.Tests
decode
function with the newstrict_depth
parameter, ensuring expected error handling for nested inputs.