From afb4a1606ab053bd0511ce6712c775c16caa7948 Mon Sep 17 00:00:00 2001 From: Andreas Lind Date: Thu, 19 Jul 2018 01:17:34 +0200 Subject: [PATCH] Tests: Extract some of the obscure strings to named vars https://github.com/ljharb/qs/pull/268#discussion_r203212750 --- test/parse.js | 21 +++++++++++++-------- 1 file changed, 13 insertions(+), 8 deletions(-) diff --git a/test/parse.js b/test/parse.js index 55b0b59b..83263d8f 100644 --- a/test/parse.js +++ b/test/parse.js @@ -582,43 +582,48 @@ test('parse()', function (t) { st.end(); }); + var urlEncodedCheckmarkInUtf8 = '%E2%9C%93'; + var urlEncodedOSlashInUtf8 = '%C3%B8'; + var urlEncodedNumCheckmark = '%26%2310003%3B'; + var urlEncodedNumSmiley = '%26%239786%3B'; + t.test('prefers an utf-8 charset specified by the utf8 sentinel to a default charset of iso-8859-1', function (st) { - st.deepEqual(qs.parse('utf8=%E2%9C%93&%C3%B8=%C3%B8', { utf8Sentinel: true, charset: 'iso-8859-1' }), { ø: 'ø' }); + st.deepEqual(qs.parse('utf8=' + urlEncodedCheckmarkInUtf8 + '&' + urlEncodedOSlashInUtf8 + '=' + urlEncodedOSlashInUtf8, { utf8Sentinel: true, charset: 'iso-8859-1' }), { ø: 'ø' }); st.end(); }); t.test('prefers an iso-8859-1 charset specified by the utf8 sentinel to a default charset of utf-8', function (st) { - st.deepEqual(qs.parse('utf8=%26%2310003%3B&%C3%B8=%C3%B8', { utf8Sentinel: true, charset: 'utf-8' }), { 'ø': 'ø' }); + st.deepEqual(qs.parse('utf8=' + urlEncodedNumCheckmark + '&' + urlEncodedOSlashInUtf8 + '=' + urlEncodedOSlashInUtf8, { utf8Sentinel: true, charset: 'utf-8' }), { 'ø': 'ø' }); st.end(); }); t.test('should ignore an utf8 sentinel with an unknown value', function (st) { - st.deepEqual(qs.parse('utf8=foo&%C3%B8=%C3%B8', { utf8Sentinel: true, charset: 'utf-8' }), { ø: 'ø' }); + st.deepEqual(qs.parse('utf8=foo&' + urlEncodedOSlashInUtf8 + '=' + urlEncodedOSlashInUtf8, { utf8Sentinel: true, charset: 'utf-8' }), { ø: 'ø' }); st.end(); }); t.test('uses the utf8 sentinel to switch to utf-8 when no default charset is given', function (st) { - st.deepEqual(qs.parse('utf8=%E2%9C%93&%C3%B8=%C3%B8', { utf8Sentinel: true }), { ø: 'ø' }); + st.deepEqual(qs.parse('utf8=' + urlEncodedCheckmarkInUtf8 + '&' + urlEncodedOSlashInUtf8 + '=' + urlEncodedOSlashInUtf8, { utf8Sentinel: true }), { ø: 'ø' }); st.end(); }); t.test('uses the utf8 sentinel to switch to iso-8859-1 when no default charset is given', function (st) { - st.deepEqual(qs.parse('utf8=%26%2310003%3B&%C3%B8=%C3%B8', { utf8Sentinel: true }), { 'ø': 'ø' }); + st.deepEqual(qs.parse('utf8=' + urlEncodedNumCheckmark + '&' + urlEncodedOSlashInUtf8 + '=' + urlEncodedOSlashInUtf8, { utf8Sentinel: true }), { 'ø': 'ø' }); st.end(); }); t.test('interprets numeric entities in iso-8859-1 when the interpretNumericEntities option is given', function (st) { - st.deepEqual(qs.parse('foo=%26%239786%3B', { charset: 'iso-8859-1', interpretNumericEntities: true }), { foo: '☺' }); + st.deepEqual(qs.parse('foo=' + urlEncodedNumSmiley, { charset: 'iso-8859-1', interpretNumericEntities: true }), { foo: '☺' }); st.end(); }); t.test('does not interpret numeric entities in iso-8859-1 when the interpretNumericEntities option is not given', function (st) { - st.deepEqual(qs.parse('foo=%26%239786%3B', { charset: 'iso-8859-1' }), { foo: '☺' }); + st.deepEqual(qs.parse('foo=' + urlEncodedNumSmiley, { charset: 'iso-8859-1' }), { foo: '☺' }); st.end(); }); t.test('does not interpret numeric entities when the charset is utf-8, even when the interpretNumericEntities option is given', function (st) { - st.deepEqual(qs.parse('foo=%26%239786%3B', { charset: 'utf-8', interpretNumericEntities: true }), { foo: '☺' }); + st.deepEqual(qs.parse('foo=' + urlEncodedNumSmiley, { charset: 'utf-8', interpretNumericEntities: true }), { foo: '☺' }); st.end(); });