Skip to content

Commit

Permalink
Fix join of enum with string
Browse files Browse the repository at this point in the history
The join of a string restricted by a pattern with an unrestricted string
is the unrestricted string, because it contains every possible string.
  • Loading branch information
kmichel-aiven committed Jun 16, 2024
1 parent 5912a05 commit 532f57b
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 4 deletions.
4 changes: 0 additions & 4 deletions jsonsubschema/_checkers.py
Original file line number Diff line number Diff line change
Expand Up @@ -359,10 +359,6 @@ def _joinString(s1, s2):
if s1_new_pattern and s2_new_pattern:
ret["pattern"] = "^" + s1_new_pattern + \
"$|^" + s2_new_pattern + "$"
elif s1_new_pattern:
ret["pattern"] = "^" + s1_new_pattern + "$"
elif s2_new_pattern:
ret["pattern"] = "^" + s2_new_pattern + "$"
return JSONTypeString(ret)
else:
return JSONanyOf({"anyOf": [s1, s2]})
Expand Down
5 changes: 5 additions & 0 deletions test/test_string.py
Original file line number Diff line number Diff line change
Expand Up @@ -212,6 +212,11 @@ def test_enum3(self):
with self.subTest():
self.assertFalse(isSubschema(s2, s1))

def test_enum4(self):
s1 = {"anyOf": [{"enum": ["a", "b", "c"]}, {"type": "string"}]}
s2 = {"type": "string"}
self.assertTrue(isEquivalent(s1, s2))

def test_not_enum1(self):
s1 = {"type": "string", "not": {"enum": ["a"]}}
s2 = {"type": "string"}
Expand Down

0 comments on commit 532f57b

Please sign in to comment.