Fix find_additional_properties ignoring an empty patternProperties key#1522
Open
vineethsaivs wants to merge 1 commit into
Open
Fix find_additional_properties ignoring an empty patternProperties key#1522vineethsaivs wants to merge 1 commit into
vineethsaivs wants to merge 1 commit into
Conversation
find_additional_properties joined all patternProperties keys into a single '|'.join(...) regex and guarded it with 'if patterns', which is falsy for an empty string. An empty-string pattern key (a valid regex matching every property) was therefore dropped, so its properties were wrongly treated as additional and validated against additionalProperties instead of the pattern subschema. The sibling find_evaluated_property_keys_by_schema already iterates the patterns individually with re.search; mirror that here.
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.
find_additional_propertiesinjsonschema/_utils.pycollapses everypatternPropertieskey into one regex with"|".join(...)and then guards it withif patterns:"|".joinmaps both an emptypatternPropertiesand{"": ...}to the same empty string, andif patternsthen treats that empty (match-everything) pattern as absent. So an empty-string pattern key, which is a valid regex that matches every property, is silently dropped: its properties are reported as additional and validated againstadditionalPropertiesinstead of the pattern subschema.The sibling helper
find_evaluated_property_keys_by_schema(used forunevaluatedProperties) already iterates the patterns individually withre.search, so the two helpers disagree on the same schema. This change makesfind_additional_propertiesdo the same: iterate thepatternPropertiesdict and skip a property if any pattern matches, which distinguishes "no patterns" (nothing to match) from an empty-string pattern (matches everything).Added
TestFindAdditionalPropertiesinjsonschema/tests/test_utils.py(fails before, passes after). The full JSON-Schema-Test-Suite still passes with no regressions.