| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -100,12 +100,29 @@ function qsUnescape(s, decodeSpaces) { | |||
| 100 | 100 | } | |
| 101 | 101 | ||
| 102 | 102 | ||
| 103 | - var hexTable = new Array(256); | ||
| 103 | + const hexTable = []; | ||
| 104 | 104 | for (var i = 0; i < 256; ++i) | |
| 105 | 105 | hexTable[i] = '%' + ((i < 16 ? '0' : '') + i.toString(16)).toUpperCase(); | |
| 106 | + | ||
| 107 | + // These characters do not need escaping when generating query strings: | ||
| 108 | + // ! - . _ ~ | ||
| 109 | + // ' ( ) * | ||
| 110 | + // digits | ||
| 111 | + // alpha (uppercase) | ||
| 112 | + // alpha (lowercase) | ||
| 113 | + const noEscape = [ | ||
| 114 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0 - 15 | ||
| 115 | + 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16 - 31 | ||
| 116 | + 0, 1, 0, 0, 0, 0, 0, 1, 1, 1, 1, 0, 0, 1, 1, 0, // 32 - 47 | ||
| 117 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 0, 0, // 48 - 63 | ||
| 118 | + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 64 - 79 | ||
| 119 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 0, 1, // 80 - 95 | ||
| 120 | + 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, // 96 - 111 | ||
| 121 | + 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 0, 0, 0, 1, 0 // 112 - 127 | ||
| 122 | + ]; | ||
| 123 | + // QueryString.escape() replaces encodeURIComponent() | ||
| 124 | + // http://www.ecma-international.org/ecma-262/5.1/#sec-15.1.3.4 | ||
| 106 | 125 | function qsEscape(str) { | |
| 107 | - // replaces encodeURIComponent | ||
| 108 | - // http://www.ecma-international.org/ecma-262/5.1/#sec-15.1.3.4 | ||
| 109 | 126 | if (typeof str !== 'string') { | |
| 110 | 127 | if (typeof str === 'object') | |
| 111 | 128 | str = String(str); | |
@@ -118,30 +135,20 @@ function qsEscape(str) { | |||
| 118 | 135 | for (var i = 0; i < str.length; ++i) { | |
| 119 | 136 | var c = str.charCodeAt(i); | |
| 120 | 137 | ||
| 121 | - // These characters do not need escaping (in order): | ||
| 122 | - // ! - . _ ~ | ||
| 123 | - // ' ( ) * | ||
| 124 | - // digits | ||
| 125 | - // alpha (uppercase) | ||
| 126 | - // alpha (lowercase) | ||
| 127 | - if (c === 0x21 || c === 0x2D || c === 0x2E || c === 0x5F || c === 0x7E || | ||
| 128 | - (c >= 0x27 && c <= 0x2A) || | ||
| 129 | - (c >= 0x30 && c <= 0x39) || | ||
| 130 | - (c >= 0x41 && c <= 0x5A) || | ||
| 131 | - (c >= 0x61 && c <= 0x7A)) { | ||
| 132 | - continue; | ||
| 133 | - } | ||
| 134 | - | ||
| 135 | - if (i - lastPos > 0) | ||
| 136 | - out += str.slice(lastPos, i); | ||
| 137 | - | ||
| 138 | - // Other ASCII characters | ||
| 138 | + // ASCII | ||
| 139 | 139 | if (c < 0x80) { | |
| 140 | + if (noEscape[c] === 1) | ||
| 141 | + continue; | ||
| 142 | + if (lastPos < i) | ||
| 143 | + out += str.slice(lastPos, i); | ||
| 140 | 144 | lastPos = i + 1; | |
| 141 | 145 | out += hexTable[c]; | |
| 142 | 146 | continue; | |
| 143 | 147 | } | |
| 144 | 148 | ||
| 149 | + if (lastPos < i) | ||
| 150 | + out += str.slice(lastPos, i); | ||
| 151 | + | ||
| 145 | 152 | // Multi-byte characters ... | |
| 146 | 153 | if (c < 0x800) { | |
| 147 | 154 | lastPos = i + 1; | |
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
@@ -95,6 +95,10 @@ const qsNoMungeTestCases = [ | |||
| 95 | 95 | ['foo=bar&foo=baz', {'foo': ['bar', 'baz']}], | |
| 96 | 96 | ['foo=bar&foo=baz', foreignObject], | |
| 97 | 97 | ['blah=burp', {'blah': 'burp'}], | |
| 98 | + ['a=!-._~\'()*', {'a': '!-._~\'()*'}], | ||
| 99 | + ['a=abcdefghijklmnopqrstuvwxyz', {'a': 'abcdefghijklmnopqrstuvwxyz'}], | ||
| 100 | + ['a=ABCDEFGHIJKLMNOPQRSTUVWXYZ', {'a': 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'}], | ||
| 101 | + ['a=0123456789', {'a': '0123456789'}], | ||
| 98 | 102 | ['gragh=1&gragh=3&goo=2', {'gragh': ['1', '3'], 'goo': '2'}], | |
| 99 | 103 | ['frappucino=muffin&goat%5B%5D=scone&pond=moose', | |
| 100 | 104 | {'frappucino': 'muffin', 'goat[]': 'scone', 'pond': 'moose'}], | |
| Back | FazBrowse Home | New Git URL |
0 commit comments