Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion fastjsonschema/draft04.py
Original file line number Diff line number Diff line change
Expand Up @@ -257,7 +257,7 @@ def generate_not(self):
else:
with self.l('try:', optimize=False):
code_len = len(self._code)
self.generate_func_code_block(not_definition, self._variable, self._variable_name)
self.generate_func_code_block(not_definition, self._variable, self._variable_name, clear_variables=True)
if len(self._code) == code_len:
self.l('pass')
self.l('except JsonSchemaValueException: pass')
Expand Down
16 changes: 16 additions & 0 deletions tests/test_common.py
Original file line number Diff line number Diff line change
Expand Up @@ -101,6 +101,22 @@ def test_not(asserter, value, expected):
asserter({'not': {'type': 'number'}}, value, expected)


@pytest.mark.parametrize('value, expected', [
({'a': 1}, {'a': 1}),
({'b': 2}, {'b': 2}),
({'a': 1, 'b': 2}, JsonSchemaValueException('data must NOT match a disallowed definition', value='{data}', name='data', definition='{definition}', rule='not')),
])
def test_not_with_object_and_additional_properties(asserter, value, expected):
# Regression test: variables created inside the not block must not leak
# into the outer scope (issue #208).
asserter({
'type': 'object',
'properties': {'a': {}, 'b': {}},
'additionalProperties': False,
'not': {'properties': {'a': {}, 'b': {}}, 'required': ['a', 'b']},
}, value, expected)


exc = JsonSchemaValueException('data must NOT match a disallowed definition', value='{data}', name='data', definition='{definition}', rule='not')
@pytest.mark.parametrize('subdefinition', [
{'title': 'x'},
Expand Down
Loading