Skip to content

Commit

Permalink
Fixes missing normalization of whitespace in schema's rule names
Browse files Browse the repository at this point in the history
  • Loading branch information
funkyfuture committed Mar 15, 2020
1 parent 31d7ffd commit a7fdbc8
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 5 deletions.
6 changes: 6 additions & 0 deletions CHANGES.rst
Original file line number Diff line number Diff line change
Expand Up @@ -6,12 +6,18 @@ Cerberus is a collaboratively funded project, see the `funding page`_.
Version 1.3.3
-------------

Unreleased.

Fixed
~~~~~~

- Fixed crash when submitting non-hashable values to ``allowed`` (`#524`_)
- Fixed schema validation for rules specifications with space (`#527`)
- Replaced deprecated rule name ``validator`` with ``check_with`` in the docs
(`#527`)

.. _`#524`: https://github.com/pyeve/cerberus/issues/524
.. _`#527`: https://github.com/pyeve/cerberus/issues/527

Version 1.3.2
-------------
Expand Down
15 changes: 10 additions & 5 deletions cerberus/schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -269,12 +269,17 @@ def _validate(self, schema):
if schema is None:
raise SchemaError(errors.SCHEMA_ERROR_MISSING)

schema = copy(schema)
for field in schema:
if isinstance(schema[field], _str_type):
schema[field] = rules_set_registry.get(schema[field], schema[field])
test_schema = {}
for field, rules in schema.items():
if isinstance(rules, _str_type):
test_schema[field] = rules_set_registry.get(rules, rules)
else:
test_rules = {}
for rule, constraint in rules.items():
test_rules[rule.replace(" ", "_")] = constraint
test_schema[field] = test_rules

if not self.schema_validator(schema, normalize=False):
if not self.schema_validator(test_schema, normalize=False):
raise SchemaError(self.schema_validator.errors)


Expand Down
6 changes: 6 additions & 0 deletions cerberus/tests/test_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -172,3 +172,9 @@ def bar(field, value, error):
assert validator.schema == {
'field': {'anyof': [{'check_with': foo}, {'check_with': bar}]}
}


def test_rulename_space_is_normalized():
validator = Validator(
schema={"field": {"default setter": lambda x: x, "type": "string"}}
)

0 comments on commit a7fdbc8

Please sign in to comment.