Fix find_additional_properties ignoring an empty patternProperties key - #1522
Fix find_additional_properties ignoring an empty patternProperties key#1522vineethsaivs 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.
|
Verified with Codex at exact head On the exact base, both externally visible cases are RED: an empty The one-commit diff also applies cleanly to current |
|
Thank you for reproducing it independently, including running the full no-extras suite on both the head and a current- To save a maintainer the re-check: the change is one commit touching @Julian, happy to rebase or split this if you would like it in a different shape. |
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.