Skip to content

Commit

Permalink
Fixed broken tests on escaped characters
Browse files Browse the repository at this point in the history
+replaced "escape" at all
  • Loading branch information
openself committed May 25, 2019
1 parent ca832b4 commit f0fe666
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion lib/utils/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ module.exports = {
comparedValue = `'${JSON.stringify(value)}'`;
$1 = fn.cache('JSON.stringify($1)');
} else if (typeof value === 'string') {
comparedValue = `'${escape(value)}'`;
comparedValue = `'${encodeURIComponent(value)}'`;
}

return `${$1} != decodeURIComponent(${comparedValue})`;
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(decodeURIComponent("${escape(dependency)}"))) {`);
tpl(`if (${tpl.data}.hasOwnProperty(decodeURIComponent("${encodeURIComponent(dependency)}"))) {`);
if (Array.isArray(value) || typeof value === 'string') {
[...value]
.map(property => `if (!${tpl.data}.hasOwnProperty(decodeURIComponent("${escape(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(decodeURIComponent("${escape(propertyKey)}"))) {`);
tpl(`if (${tpl.data}.hasOwnProperty(decodeURIComponent("${encodeURIComponent(propertyKey)}"))) {`);
}

tpl.data.push(`[decodeURIComponent('${escape(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(decodeURIComponent("${escape(name)}"))`;
const condition = `!${tpl.data}.hasOwnProperty(decodeURIComponent("${encodeURIComponent(name)}"))`;
const error = tpl.error('required', name);
return `if (${condition}) ${error}`;
}).join('')}
Expand Down

0 comments on commit f0fe666

Please sign in to comment.