Skip to content

Commit bd9bc06

Browse files
committed
Avoid unescaping %uXXXX in iso-8859-1 mode
ljharb#268 (comment)
1 parent afb4a16 commit bd9bc06

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

lib/utils.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,8 @@ var assign = function assignSingleSource(target, source) {
110110
var decode = function (str, decoder, charset) {
111111
var strWithoutPlus = str.replace(/\+/g, ' ');
112112
if (charset === 'iso-8859-1') {
113-
return unescape(strWithoutPlus); // Cannot throw
113+
// unescape never throws, no try...catch needed:
114+
return strWithoutPlus.replace(/%[0-9a-f]{2}/gi, unescape);
114115
}
115116
// utf-8
116117
try {

test/parse.js

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -627,5 +627,10 @@ test('parse()', function (t) {
627627
st.end();
628628
});
629629

630+
t.test('does not interpret %uXXXX syntax in iso-8859-1 mode', function (st) {
631+
st.deepEqual(qs.parse('%u263A=%u263A', { charset: 'iso-8859-1' }), { '%u263A': '%u263A' });
632+
st.end();
633+
});
634+
630635
t.end();
631636
});

0 commit comments

Comments
 (0)