use properties as properties or indeces correctly in all cases

master
Evgeny Poberezkin 2015-06-24 00:43:52 +01:00
parent 3b815d6862
commit 0ccf7e73f1
6 changed files with 6 additions and 12 deletions

View File

@ -7,7 +7,6 @@ module.exports = {
checkDataTypes: checkDataTypes,
toHash: toHash,
getProperty: getProperty,
escapeQuotes: escapeQuotes,
escapeRegExp: escapeRegExp,
ucs2length: ucs2length,
varOccurences: varOccurences,
@ -85,12 +84,7 @@ var IDENTIFIER = /^[a-z$_][a-z$_0-9]*$/i;
function getProperty(key) {
return IDENTIFIER.test(key)
? '.' + key
: "['" + key + "']";
}
function escapeQuotes(str) {
return str.replace(/'/g, "\\'");
: "['" + key.replace(/'/g, "\\'") + "']";
}

View File

@ -41,7 +41,7 @@ var {{=$errs}} = errors;
if ({{=$data}}['{{= $property }}'] !== undefined) {
{{
$it.schema = $sch;
$it.schemaPath = $schemaPath + "['" + it.util.escapeQuotes($property) + "']";
$it.schemaPath = $schemaPath + it.util.getProperty($property);
}}
{{= it.validate($it) }}

View File

@ -79,9 +79,9 @@ var valid{{=$it.level}} = true;
{{? {{# def.nonEmptySchema:$sch}} }}
{{
$it.schema = $sch;
$it.schemaPath = $schemaPath + "['" + it.util.escapeQuotes($propertyKey) + "']";
var $prop = it.util.getProperty($propertyKey)
, $passData = $data + $prop;
$it.schemaPath = $schemaPath + $prop;
$it.errorPath = (it.errorPath + ' + "' + $prop + '"').replace('" + "', '');
$it.dataPath = it.dataPath + $prop;
}}

View File

@ -77,7 +77,7 @@ module.exports = function anonymous(it) {
if (it.util.schemaHasRules($sch, it.RULES.all)) {
out += ' valid' + ($it.level) + ' = true; if (' + ($data) + '[\'' + ($property) + '\'] !== undefined) { ';
$it.schema = $sch;
$it.schemaPath = $schemaPath + "['" + it.util.escapeQuotes($property) + "']";
$it.schemaPath = $schemaPath + it.util.getProperty($property);
out += ' ' + (it.validate($it)) + ' } ';
if ($breakOnError) {
out += ' if (valid' + ($it.level) + ') { ';

View File

@ -94,9 +94,9 @@ module.exports = function anonymous(it) {
var $sch = $schema[$propertyKey];
if (it.util.schemaHasRules($sch, it.RULES.all)) {
$it.schema = $sch;
$it.schemaPath = $schemaPath + "['" + it.util.escapeQuotes($propertyKey) + "']";
var $prop = it.util.getProperty($propertyKey),
$passData = $data + $prop;
$it.schemaPath = $schemaPath + $prop;
$it.errorPath = (it.errorPath + ' + "' + $prop + '"').replace('" + "', '');
$it.dataPath = it.dataPath + $prop;
var $code = it.validate($it);

View File

@ -1,6 +1,6 @@
{
"name": "ajv",
"version": "0.5.11",
"version": "0.5.12",
"description": "Another JSON Schema Validator",
"main": "lib/ajv.js",
"scripts": {