Commits

Ian Lewis committed 71c2cb1

Fixed bug that allowed None values even though they were disallowed by additionalProperties

Comments (0)

Files changed (1)

jsonschema/validator.py

   def validate_additionalProperties(self, x, fieldname, schema, additionalProperties=None):
     '''Validates additional properties of a JSON object that were not
        specifically defined by the properties property'''
-    if additionalProperties is not None and x.get(fieldname) is not None:
+    if additionalProperties is not None:
       # If additionalProperties is the boolean value True then we accept any
       # additional properties.
       if isinstance(additionalProperties, types.BooleanType) and additionalProperties == True:
         return x
       
       value = x.get(fieldname)
-      if value is not None:
-        if isinstance(value, types.DictType):
-          if isinstance(additionalProperties, types.DictType) \
-           or isinstance(additionalProperties, types.BooleanType):
-            properties = schema.get("properties")
-            if properties is None:
-              properties = {}
-            for eachProperty in value.keys():
-              if eachProperty not in properties:
-                # If additionalProperties is the boolean value False then we 
-                # don't accept any additional properties.
-                if isinstance(additionalProperties, types.BooleanType) and additionalProperties == False:
-                  raise ValueError("Additional properties not defined by the 'properties' property are not allowed in %s" % fieldname)
-                self.__validate(eachProperty, value, additionalProperties)
-          else:
-            raise ValueError("additionalProperties schema definition for %s is not an object" % fieldname)
+      if isinstance(additionalProperties, types.DictType) \
+       or isinstance(additionalProperties, types.BooleanType):
+        properties = schema.get("properties")
+        if properties is None:
+          properties = {}
+        for eachProperty in value.keys():
+          if eachProperty not in properties:
+            # If additionalProperties is the boolean value False then we 
+            # don't accept any additional properties.
+            if isinstance(additionalProperties, types.BooleanType) and additionalProperties == False:
+              raise ValueError("Additional properties not defined by the 'properties' property are not allowed in %s" % fieldname)
+            self.__validate(eachProperty, value, additionalProperties)
+      else:
+        raise ValueError("additionalProperties schema definition for %s is not an object" % fieldname)
     return x
   
   def validate_requires(self, x, fieldname, schema, requires=None):