diff --git a/jsonschema/_validators.py b/jsonschema/_validators.py index 4b45785..d0baec8 100644 --- a/jsonschema/_validators.py +++ b/jsonschema/_validators.py @@ -30,13 +30,16 @@ def additionalProperties(validator, aP, instance, schema): yield error elif not aP and extras: if "patternProperties" in schema: - patterns = sorted(schema["patternProperties"].keys()) + patterns = sorted(schema["patternProperties"]) if len(extras) == 1: verb = "does" else: verb = "do" - error = "%s %s not match any of the regexs: %s" % ( - ", ".join(map(repr, sorted(extras))), verb, ", ".join(patterns)) + error = "%s %s not match any of the regexes: %s" % ( + ", ".join(map(repr, sorted(extras))), + verb, + ", ".join(map(repr, patterns)), + ) yield ValidationError(error) else: error = "Additional properties are not allowed (%s %s unexpected)" diff --git a/jsonschema/tests/test_validators.py b/jsonschema/tests/test_validators.py index 432702f..fb59b83 100644 --- a/jsonschema/tests/test_validators.py +++ b/jsonschema/tests/test_validators.py @@ -195,21 +195,25 @@ class TestValidationErrorMessages(unittest.TestCase): schema = {u"type": u"object", u"additionalProperties": False, u"patternProperties": { - u"$abc^": {u"type": u"string"}, - u"$def^": {u"type": u"string"} + u"^abc$": {u"type": u"string"}, + u"^def$": {u"type": u"string"} }} message = self.message_for({u"zebra": 123}, schema, cls=Draft4Validator) self.assertEqual( message, - "{} does not match any of the regexs: $abc^, $def^".format( - repr(u"zebra"))) + "{} does not match any of the regexes: {}, {}".format( + repr(u"zebra"), repr(u"^abc$"), repr(u"^def$"), + ), + ) message = self.message_for({u"zebra": 123, u"fish": 456}, schema, cls=Draft4Validator) self.assertEqual( message, - "{}, {} do not match any of the regexs: $abc^, $def^".format( - repr(u"fish"), repr(u"zebra"))) + "{}, {} do not match any of the regexes: {}, {}".format( + repr(u"fish"), repr(u"zebra"), repr(u"^abc$"), repr(u"^def$") + ), + ) class TestValidationErrorDetails(unittest.TestCase):