Skip to content

Commit

Permalink
Merge branch 'master' of https://github.com/korzio/djv
Browse files Browse the repository at this point in the history
  • Loading branch information
korzio committed May 25, 2019
2 parents 46bfdbe + f91b01c commit 4b3fd50
Show file tree
Hide file tree
Showing 8 changed files with 52 additions and 25 deletions.
2 changes: 1 addition & 1 deletion djv.js

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion djv.js.map

Large diffs are not rendered by default.

4 changes: 2 additions & 2 deletions lib/utils/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,10 +85,10 @@ module.exports = {
comparedValue = `'${JSON.stringify(value)}'`;
$1 = fn.cache('JSON.stringify($1)');
} else if (typeof value === 'string') {
comparedValue = `'${value}'`;
comparedValue = `'${encodeURIComponent(value)}'`;
}

return `${$1} !== ${comparedValue}`;
return `${$1} != decodeURIComponent(${comparedValue})`;
}).join(' && ');
}
};
18 changes: 13 additions & 5 deletions lib/utils/template.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,20 +37,28 @@ function template(state, options) {
const error = typeof options.errorHandler === 'function' ?
options.errorHandler :
function defaultErrorHandler(errorType) {
const path = this.data.toString().replace(/^data/, '');
const path = this.data.toString()
.replace(/^data/, '');
const dataPath = path
.replace(/\['([^']+)'\]/ig, '.$1')
.replace(/\[(i[0-9]*)\]/ig, '[\'+$1+\']');
const schemaPath = `#${
path
.replace(/\[i([0-9]*)\]/ig, '/items')
.replace(/\['([^']+)'\]/ig, '/properties/$1')
}/${errorType}`;

}/${errorType}`;
function clearDecode(tplString) {
return tplString
.replace('[', '')
.replace(']', '')
.replace('(', '')
.replace(')', '')
.replace('decodeURIComponent', '');
}
return `return {
keyword: '${errorType}',
dataPath: '${dataPath}',
schemaPath: '${schemaPath}'
dataPath: decodeURIComponent("${clearDecode(dataPath)}"),
schemaPath: decodeURIComponent("${clearDecode(schemaPath)}")
};`;
};

Expand Down
4 changes: 2 additions & 2 deletions lib/validators/dependencies.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ module.exports = function dependencies(schema, tpl) {
const value = schema.dependencies[dependency];
const error = tpl.error('dependencies');

tpl(`if (${tpl.data}.hasOwnProperty("${dependency}")) {`);
tpl(`if (${tpl.data}.hasOwnProperty(decodeURIComponent("${encodeURIComponent(dependency)}"))) {`);
if (Array.isArray(value) || typeof value === 'string') {
[...value]
.map(property => `if (!${tpl.data}.hasOwnProperty("${property}")) ${error}`)
.map(property => `if (!${tpl.data}.hasOwnProperty(decodeURIComponent("${encodeURIComponent(property)}"))) ${error}`)
.map(tpl);
} else if (isSchema(value)) {
tpl.visit(value);
Expand Down
4 changes: 2 additions & 2 deletions lib/validators/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,10 +14,10 @@ module.exports = function properties(schema, tpl) {

const isNotRequired = !schema.required || schema.required.indexOf(propertyKey) === -1;
if (isNotRequired) {
tpl(`if (${tpl.data}.hasOwnProperty("${propertyKey}")) {`);
tpl(`if (${tpl.data}.hasOwnProperty(decodeURIComponent("${encodeURIComponent(propertyKey)}"))) {`);
}

tpl.data.push(`['${propertyKey}']`);
tpl.data.push(`[decodeURIComponent('${encodeURIComponent(propertyKey)}')]`);
tpl.visit(propertySchema);
tpl.data.pop();

Expand Down
2 changes: 1 addition & 1 deletion lib/validators/required.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ module.exports = function required(schema, tpl) {

tpl(`if (${tpl.data} !== null && typeof ${tpl.data} === 'object' && !Array.isArray(${tpl.data})) {
${schema.required.map((name) => {
const condition = `!${tpl.data}.hasOwnProperty("${name}")`;
const condition = `!${tpl.data}.hasOwnProperty(decodeURIComponent("${encodeURIComponent(name)}"))`;
const error = tpl.error('required', name);
return `if (${condition}) ${error}`;
}).join('')}
Expand Down
41 changes: 30 additions & 11 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

0 comments on commit 4b3fd50

Please sign in to comment.