Skip to content
This repository was archived by the owner on Jan 7, 2021. It is now read-only.

Commit da94d5d

Browse files
committed
Fixes #52 making sure it sanitizes all the occurrences.
Sanitize function was only replacing the first special character found. This changes makes sure it sanitizes all the occurrences of a special characters.
1 parent 8a4718e commit da94d5d

1 file changed

Lines changed: 5 additions & 1 deletion

File tree

lib/sanitize.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,13 +23,17 @@ var chars = {
2323
"'": '''
2424
};
2525

26+
function escapeRegExp(string) {
27+
return string.replace(/([.*+?^=!:${}()|\[\]\/\\])/g, "\\$1");
28+
}
29+
2630
exports.sanitize = function sanitize(value) {
2731
if (typeof value !== 'string') {
2832
return value;
2933
}
3034

3135
Object.keys(chars).forEach(function(key) {
32-
value = value.replace(key, chars[key]);
36+
value = value.replace(new RegExp(escapeRegExp(key), 'g'), chars[key]);
3337
});
3438

3539
return value;

0 commit comments

Comments
 (0)