From a7fdbc89053bac3d34c53db0d6e311e4ef66fb7e Mon Sep 17 00:00:00 2001 From: Frank Sachsenheim Date: Fri, 6 Mar 2020 20:49:49 +0100 Subject: [PATCH] Fixes missing normalization of whitespace in schema's rule names --- CHANGES.rst | 6 ++++++ cerberus/schema.py | 15 ++++++++++----- cerberus/tests/test_schema.py | 6 ++++++ 3 files changed, 22 insertions(+), 5 deletions(-) diff --git a/CHANGES.rst b/CHANGES.rst index 4f27ff40..0d43cff4 100644 --- a/CHANGES.rst +++ b/CHANGES.rst @@ -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 ------------- diff --git a/cerberus/schema.py b/cerberus/schema.py index 3841384e..2e4b5071 100644 --- a/cerberus/schema.py +++ b/cerberus/schema.py @@ -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) diff --git a/cerberus/tests/test_schema.py b/cerberus/tests/test_schema.py index 509f446f..a301b12c 100644 --- a/cerberus/tests/test_schema.py +++ b/cerberus/tests/test_schema.py @@ -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"}} + )