Skip to content

Commit

Permalink
Escape backslash, closes #516
Browse files Browse the repository at this point in the history
  • Loading branch information
chriso committed Sep 27, 2016
1 parent e33d38a commit 534a35e
Show file tree
Hide file tree
Showing 6 changed files with 9 additions and 3 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

- Renamed `isNull()` to `isEmpty()`
([#574](https://github.com/chriso/validator.js/issues/574))
- Backslash is now escaped in `escape()`
([#516](https://github.com/chriso/validator.js/issues/516))
- Improved `normalizeEmail()`
([#583](https://github.com/chriso/validator.js/pull/583))

Expand Down
2 changes: 1 addition & 1 deletion lib/escape.js
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,6 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de

function escape(str) {
(0, _assertString2.default)(str);
return str.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#x27;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\//g, '&#x2F;').replace(/`/g, '&#96;');
return str.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#x27;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\//g, '&#x2F;').replace(/\\/g, '&#x5C;').replace(/`/g, '&#96;');
}
module.exports = exports['default'];
1 change: 1 addition & 0 deletions src/lib/escape.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,5 +8,6 @@ export default function escape(str) {
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/\//g, '&#x2F;')
.replace(/\\/g, '&#x5C;')
.replace(/`/g, '&#96;'));
}
3 changes: 3 additions & 0 deletions test/sanitizers.js
Original file line number Diff line number Diff line change
Expand Up @@ -139,6 +139,9 @@ describe('Sanitizers', function () {

'Backtick: `':
'Backtick: &#96;',

'Backslash: \\':
'Backslash: &#x5C;',
},
});
});
Expand Down
2 changes: 1 addition & 1 deletion validator.js
Original file line number Diff line number Diff line change
Expand Up @@ -1077,7 +1077,7 @@

function escape(str) {
assertString(str);
return str.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#x27;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\//g, '&#x2F;').replace(/`/g, '&#96;');
return str.replace(/&/g, '&amp;').replace(/"/g, '&quot;').replace(/'/g, '&#x27;').replace(/</g, '&lt;').replace(/>/g, '&gt;').replace(/\//g, '&#x2F;').replace(/\\/g, '&#x5C;').replace(/`/g, '&#96;');
}

function unescape(str) {
Expand Down
2 changes: 1 addition & 1 deletion validator.min.js

Large diffs are not rendered by default.

0 comments on commit 534a35e

Please sign in to comment.