bpdusk / jsonschema

Automatically exported from code.google.com/p/jsonschema
0 stars 0 forks source link

disallow is not working #10

Closed GoogleCodeExporter closed 8 years ago

GoogleCodeExporter commented 8 years ago
when you have a disallow property, its not working because of the following
check:

if (schema.disallow && !checkType(schema.disallow,value).length)
  addError(" disallowed value was matched");

The following:

!checkType(schema.disallow,value).length

is not enougth because althought the checkType function only returns an
array of errors, it has a call for the checkProp method that register some
erros on another scope. 

I see two solutions for this, I guess the best one is to make the checkProp
and checkObj return arrays of errors, but it involves a lot more refactoring. 

The second one, that I did in the php implementation for now, is to just
supress the erros or to ignore the errors registered by the disallow´s call
to check prop. 

Here is the PHP code I have used for this now, its very easy to port:

    if(array_key_exists('disallow',$schema)) {
      $errorsBeforeDisallowCheck = self::$errors;
      $response = self::checkType($schema->disallow, $value, $path);
      // check if had any response AND if changed the 'global' errors.
      if(
        ( count($errorsBeforeDisallowCheck) == count(self::$errors) )  &&
        !count($response)
      ) {
        self::adderror($path," disallowed value was matched");
      }
      else {
        // return the global errors to its state before the check
        self::$errors = $errorsBeforeDisallowCheck;
      }
    }

Original issue reported on code.google.com by bruno.p.reis@gmail.com on 5 Dec 2008 at 9:06

GoogleCodeExporter commented 8 years ago

Original comment by kris...@gmail.com on 16 Apr 2009 at 8:39