Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(unescape-bug): Fixed bug where intermediate string contains escaped characters #1835

Merged
merged 2 commits into from Oct 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 6 additions & 3 deletions src/lib/unescape.js
Expand Up @@ -2,12 +2,15 @@ import assertString from './util/assertString';

export default function unescape(str) {
assertString(str);
return (str.replace(/&/g, '&')
.replace(/"/g, '"')
return (str.replace(/"/g, '"')
.replace(/'/g, "'")
.replace(/&lt;/g, '<')
.replace(/&gt;/g, '>')
.replace(/&#x2F;/g, '/')
.replace(/&#x5C;/g, '\\')
.replace(/&#96;/g, '`'));
.replace(/&#96;/g, '`')
.replace(/&amp;/g, '&'));
Marcholio marked this conversation as resolved.
Show resolved Hide resolved
// &amp; replacement has to be the last one to prevent
// bugs with intermediate strings containing escape sequences
// See: https://github.com/validatorjs/validator.js/issues/1827
}
3 changes: 3 additions & 0 deletions test/sanitizers.js
Expand Up @@ -184,6 +184,9 @@ describe('Sanitizers', () => {

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

'Escaped string: &amp;lt;':
'Escaped string: &lt;',
},
});
});
Expand Down