<p>When encoding a query string to be sent to a web server - when do you use <code>escape()</code> and when do you use <code>encodeURI()</code> or <code>encodeURIComponent()</code>:</p>

<p>Use escape:</p>

<pre><code>escape("% +&amp;=");
</code></pre>

<p>OR</p>

<p>use encodeURI() / encodeURIComponent()</p>

<pre><code>encodeURI("http://www.google.com?var1=value1&amp;var2=value2");

encodeURIComponent("var1=value1&amp;var2=value2");
</code></pre>

[{'answer_id': 75989, 'author': 'Daniel Papasian', 'author_id': 7548, 'author_profile': 'https://Stackoverflow.com/users/7548', 'pm_score': 5, 'selected': False, 'text': '<p>encodeURI() - the escape() function is for javascript escaping, not HTTP.</p>\n'}, {'answer_id': 76119, 'author': 'Pseudo Masochist', 'author_id': 8529, 'author_profile': 'https://Stackoverflow.com/users/8529', 'pm_score': 3, 'selected': False, 'text': "<p>Also remember that they all encode different sets of characters, and select the one you need appropriately.  encodeURI() encodes fewer characters than encodeURIComponent(), which encodes fewer (and also different, to dannyp's point) characters than escape().</p>\n"}, {'answer_id': 3608791, 'author': 'Arne Evertsson', 'author_id': 16686, 'author_profile': 'https://Stackoverflow.com/users/16686', 'pm_score': 12, 'selected': True, 'text': '<h1>escape()</h1>\n<p>Don\'t use it!\n<code>escape()</code> is defined in section <a href="https://www.ecma-international.org/ecma-262/9.0/index.html#sec-escape-string" rel="noreferrer">B.2.1.2 escape</a> and the <a href="https://www.ecma-international.org/ecma-262/9.0/index.html#sec-additional-ecmascript-features-for-web-browsers" rel="noreferrer">introduction text of Annex B</a> says:</p>\n<blockquote>\n<p>... All of the language features and behaviours specified in this annex have one or more undesirable characteristics and in the absence of legacy usage would be removed from this specification. ...<br />\n... Programmers should not use or assume the existence of these features and behaviours when writing new ECMAScript code....</p>\n</blockquote>\n<p>Behaviour:</p>\n<p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape" rel="noreferrer">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/escape</a></p>\n<p>Special characters are encoded with the exception of: @*_+-./</p>\n<p>The hexadecimal form for characters, whose code unit value is 0xFF or less, is a two-digit escape sequence: <code>%xx</code>.</p>\n<p>For characters with a greater code unit, the four-digit format <code>%uxxxx</code> is used. This is not allowed within a query string (as defined in <a href="https://www.rfc-editor.org/rfc/rfc3986#section-3.4" rel="noreferrer">RFC3986</a>):</p>\n<pre><code>query       = *( pchar / &quot;/&quot; / &quot;?&quot; )\npchar         = unreserved / pct-encoded / sub-delims / &quot;:&quot; / &quot;@&quot;\nunreserved    = ALPHA / DIGIT / &quot;-&quot; / &quot;.&quot; / &quot;_&quot; / &quot;~&quot;\npct-encoded   = &quot;%&quot; HEXDIG HEXDIG\nsub-delims    = &quot;!&quot; / &quot;$&quot; / &quot;&amp;&quot; / &quot;\'&quot; / &quot;(&quot; / &quot;)&quot;\n              / &quot;*&quot; / &quot;+&quot; / &quot;,&quot; / &quot;;&quot; / &quot;=&quot;\n</code></pre>\n<p>A percent sign is only allowed if it is directly followed by two hexdigits, percent followed by <code>u</code> is not allowed.</p>\n<h1>encodeURI()</h1>\n<p>Use encodeURI when you want a working URL. Make this call:</p>\n<pre><code>encodeURI(&quot;http://www.example.org/a file with spaces.html&quot;)\n</code></pre>\n<p>to get:</p>\n<pre><code>http://www.example.org/a%20file%20with%20spaces.html\n</code></pre>\n<p>Don\'t call encodeURIComponent since it would destroy the URL and return</p>\n<pre><code>http%3A%2F%2Fwww.example.org%2Fa%20file%20with%20spaces.html\n</code></pre>\n<p>Note that encodeURI, like encodeURIComponent, does not escape the \' character.</p>\n<h1>encodeURIComponent()</h1>\n<p>Use encodeURIComponent when you want to encode the value of a URL parameter.</p>\n<pre><code>var p1 = encodeURIComponent(&quot;http://example.org/?a=12&amp;b=55&quot;)\n</code></pre>\n<p>Then you may create the URL you need:</p>\n<pre><code>var url = &quot;http://example.net/?param1=&quot; + p1 + &quot;&amp;param2=99&quot;;\n</code></pre>\n<p>And you will get this complete URL:</p>\n<p><code>http://example.net/?param1=http%3A%2F%2Fexample.org%2F%Ffa%3D12%26b%3D55&amp;param2=99</code></p>\n<p>Note that encodeURIComponent does not escape the <code>\'</code> character. A common bug is to use it to create html attributes such as <code>href=\'MyUrl\'</code>, which could suffer an injection bug. If you are constructing html from strings, either use <code>&quot;</code> instead of <code>\'</code> for attribute quotes, or add an extra layer of encoding (<code>\'</code> can be encoded as %27).</p>\n<p>For more information on this type of encoding you can check: <a href="http://en.wikipedia.org/wiki/Percent-encoding" rel="noreferrer">http://en.wikipedia.org/wiki/Percent-encoding</a></p>\n'}, {'answer_id': 12796866, 'author': 'Damien', 'author_id': 438970, 'author_profile': 'https://Stackoverflow.com/users/438970', 'pm_score': 6, 'selected': False, 'text': '<p>I found this article enlightening :\n<a href="http://unixpapa.com/js/querystring.html" rel="noreferrer">Javascript Madness: Query String Parsing</a></p>\n\n<p>I found it when I was trying to undersand why decodeURIComponent was not decoding \'+\' correctly. Here is an extract:</p>\n\n<pre><code>String:                         "A + B"\nExpected Query String Encoding: "A+%2B+B"\nescape("A + B") =               "A%20+%20B"     Wrong!\nencodeURI("A + B") =            "A%20+%20B"     Wrong!\nencodeURIComponent("A + B") =   "A%20%2B%20B"   Acceptable, but strange\n\nEncoded String:                 "A+%2B+B"\nExpected Decoding:              "A + B"\nunescape("A+%2B+B") =           "A+++B"       Wrong!\ndecodeURI("A+%2B+B") =          "A+++B"       Wrong!\ndecodeURIComponent("A+%2B+B") = "A+++B"       Wrong!\n</code></pre>\n'}, {'answer_id': 16435373, 'author': 'Kirankumar Sripati', 'author_id': 2191887, 'author_profile': 'https://Stackoverflow.com/users/2191887', 'pm_score': 5, 'selected': False, 'text': '<p>encodeURIComponent doesn\'t encode <code>-_.!~*\'()</code>, causing problem in posting data to php in xml string.</p>\n\n<p>For example:<br/>\n<code>&lt;xml&gt;&lt;text x="100" y="150" value="It\'s a value with single quote" /&gt;\n&lt;/xml&gt;</code></p>\n\n<p>General escape with <code>encodeURI</code><br/>\n<code>%3Cxml%3E%3Ctext%20x=%22100%22%20y=%22150%22%20value=%22It\'s%20a%20value%20with%20single%20quote%22%20/%3E%20%3C/xml%3E</code></p>\n\n<p>You can see, single quote is not encoded.\nTo resolve issue I created two functions to solve issue in my project, for Encoding URL:</p>\n\n<pre><code>function encodeData(s:String):String{\n    return encodeURIComponent(s).replace(/\\-/g, "%2D").replace(/\\_/g, "%5F").replace(/\\./g, "%2E").replace(/\\!/g, "%21").replace(/\\~/g, "%7E").replace(/\\*/g, "%2A").replace(/\\\'/g, "%27").replace(/\\(/g, "%28").replace(/\\)/g, "%29");\n}\n</code></pre>\n\n<p>For Decoding URL:</p>\n\n<pre><code>function decodeData(s:String):String{\n    try{\n        return decodeURIComponent(s.replace(/\\%2D/g, "-").replace(/\\%5F/g, "_").replace(/\\%2E/g, ".").replace(/\\%21/g, "!").replace(/\\%7E/g, "~").replace(/\\%2A/g, "*").replace(/\\%27/g, "\'").replace(/\\%28/g, "(").replace(/\\%29/g, ")"));\n    }catch (e:Error) {\n    }\n    return "";\n}\n</code></pre>\n'}, {'answer_id': 17235463, 'author': 'molokoloco', 'author_id': 174449, 'author_profile': 'https://Stackoverflow.com/users/174449', 'pm_score': 1, 'selected': False, 'text': '<p>I have this function...</p>\n\n<pre><code>var escapeURIparam = function(url) {\n    if (encodeURIComponent) url = encodeURIComponent(url);\n    else if (encodeURI) url = encodeURI(url);\n    else url = escape(url);\n    url = url.replace(/\\+/g, \'%2B\'); // Force the replacement of "+"\n    return url;\n};\n</code></pre>\n'}, {'answer_id': 18126158, 'author': 'veeTrain', 'author_id': 469643, 'author_profile': 'https://Stackoverflow.com/users/469643', 'pm_score': 2, 'selected': False, 'text': '<p>I\'ve found that experimenting with the various methods is a good sanity check even after having a good handle of what their various uses and capabilities are.</p>\n\n<p>Towards that end I have found <a href="http://www.the-art-of-web.com/javascript/escape/" rel="nofollow">this website</a> extremely useful to confirm my suspicions that I am doing something appropriately. It has also proven useful for decoding an encodeURIComponent\'ed string which can be rather challenging to interpret. A great bookmark to have:</p>\n\n<p><a href="http://www.the-art-of-web.com/javascript/escape/" rel="nofollow">http://www.the-art-of-web.com/javascript/escape/</a></p>\n'}, {'answer_id': 23250699, 'author': 'Jerry Joseph', 'author_id': 1001217, 'author_profile': 'https://Stackoverflow.com/users/1001217', 'pm_score': 4, 'selected': False, 'text': '<p>I recommend not to use one of those methods as is. Write your own function which does the right thing.</p>\n\n<p>MDN has given a good example on url encoding shown below.</p>\n\n<pre><code>var fileName = \'my file(2).txt\';\nvar header = "Content-Disposition: attachment; filename*=UTF-8\'\'" + encodeRFC5987ValueChars(fileName);\n\nconsole.log(header); \n// logs "Content-Disposition: attachment; filename*=UTF-8\'\'my%20file%282%29.txt"\n\n\nfunction encodeRFC5987ValueChars (str) {\n    return encodeURIComponent(str).\n        // Note that although RFC3986 reserves "!", RFC5987 does not,\n        // so we do not need to escape it\n        replace(/[\'()]/g, escape). // i.e., %27 %28 %29\n        replace(/\\*/g, \'%2A\').\n            // The following are not required for percent-encoding per RFC5987, \n            //  so we can allow for a little better readability over the wire: |`^\n            replace(/%(?:7C|60|5E)/g, unescape);\n}\n</code></pre>\n\n<p><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent" rel="noreferrer">https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent</a></p>\n'}, {'answer_id': 23842171, 'author': 'Johann Echavarria', 'author_id': 2391782, 'author_profile': 'https://Stackoverflow.com/users/2391782', 'pm_score': 9, 'selected': False, 'text': '<p>The difference between <code>encodeURI()</code> and <code>encodeURIComponent()</code> are exactly 11 characters encoded by encodeURIComponent but not by encodeURI:</p>\n\n<p><img src="https://i.imgur.com/rHWC1r1.png" alt="Table with the ten differences between encodeURI and encodeURIComponent"></p>\n\n<p>I generated this table easily with <strong>console.table</strong> in Google Chrome with this code:</p>\n\n<p><div class="snippet" data-lang="js" data-hide="false" data-console="false" data-babel="false">\r\n<div class="snippet-code">\r\n<pre class="snippet-code-js lang-js prettyprint-override"><code>var arr = [];\r\nfor(var i=0;i&lt;256;i++) {\r\n  var char=String.fromCharCode(i);\r\n  if(encodeURI(char)!==encodeURIComponent(char)) {\r\n    arr.push({\r\n      character:char,\r\n      encodeURI:encodeURI(char),\r\n      encodeURIComponent:encodeURIComponent(char)\r\n    });\r\n  }\r\n}\r\nconsole.table(arr);</code></pre>\r\n</div>\r\n</div>\r\n</p>\n'}, {'answer_id': 33019871, 'author': '30thh', 'author_id': 608164, 'author_profile': 'https://Stackoverflow.com/users/608164', 'pm_score': 4, 'selected': False, 'text': "<p>Small comparison table Java vs. JavaScript vs. PHP.</p>\n\n<pre><code>1. Java URLEncoder.encode (using UTF8 charset)\n2. JavaScript encodeURIComponent\n3. JavaScript escape\n4. PHP urlencode\n5. PHP rawurlencode\n\nchar   JAVA JavaScript --PHP---\n[ ]     +    %20  %20  +    %20\n[!]     %21  !    %21  %21  %21\n[*]     *    *    *    %2A  %2A\n[']     %27  '    %27  %27  %27 \n[(]     %28  (    %28  %28  %28\n[)]     %29  )    %29  %29  %29\n[;]     %3B  %3B  %3B  %3B  %3B\n[:]     %3A  %3A  %3A  %3A  %3A\n[@]     %40  %40  @    %40  %40\n[&amp;]     %26  %26  %26  %26  %26\n[=]     %3D  %3D  %3D  %3D  %3D\n[+]     %2B  %2B  +    %2B  %2B\n[$]     %24  %24  %24  %24  %24\n[,]     %2C  %2C  %2C  %2C  %2C\n[/]     %2F  %2F  /    %2F  %2F\n[?]     %3F  %3F  %3F  %3F  %3F\n[#]     %23  %23  %23  %23  %23\n[[]     %5B  %5B  %5B  %5B  %5B\n[]]     %5D  %5D  %5D  %5D  %5D\n----------------------------------------\n[~]     %7E  ~    %7E  %7E  ~\n[-]     -    -    -    -    -\n[_]     _    _    _    _    _\n[%]     %25  %25  %25  %25  %25\n[\\]     %5C  %5C  %5C  %5C  %5C\n----------------------------------------\nchar  -JAVA-  --JavaScript--  -----PHP------\n[ä]   %C3%A4  %C3%A4  %E4     %C3%A4  %C3%A4\n[ф]   %D1%84  %D1%84  %u0444  %D1%84  %D1%84\n</code></pre>\n"}, {'answer_id': 43537042, 'author': 'Gaurav Tiwari', 'author_id': 7220283, 'author_profile': 'https://Stackoverflow.com/users/7220283', 'pm_score': 3, 'selected': False, 'text': '<p>For the purpose of encoding javascript has given three inbuilt functions -</p>\n\n<ol>\n<li><p><code>escape()</code> - does not encode <code>@*/+</code>\nThis method is deprecated after the ECMA 3 so it should be avoided.</p></li>\n<li><p><code>encodeURI()</code> - does not encode <code>~!@#$&amp;*()=:/,;?+\'</code>\nIt assumes that the URI is a complete URI, so does not encode reserved characters that have special meaning in the URI.\nThis method is used when the intent is to convert the complete URL instead of some special segment of URL.\nExample - <code>encodeURI(\'http://stackoverflow.com\');</code>\nwill give - <a href="http://stackoverflow.com">http://stackoverflow.com</a></p></li>\n<li><p><code>encodeURIComponent()</code> - does not encode  <code>- _ . ! ~ * \' ( )</code>\nThis function encodes a Uniform Resource Identifier (URI) component by replacing each instance of certain characters by one, two, three, or four escape sequences representing the UTF-8 encoding of the character. This method should be used to convert a component of URL. For instance some user input needs to be appended\nExample - <code>encodeURIComponent(\'http://stackoverflow.com\');</code>\nwill give - http%3A%2F%2Fstackoverflow.com</p></li>\n</ol>\n\n<p><em>All this encoding is performed in UTF 8 i.e the characters will be converted in UTF-8 format.</em> </p>\n\n<p><strong><em>encodeURIComponent differ from encodeURI in that it encode reserved characters and Number sign # of encodeURI</em></strong></p>\n'}, {'answer_id': 46441344, 'author': 'Michael', 'author_id': 599912, 'author_profile': 'https://Stackoverflow.com/users/599912', 'pm_score': 2, 'selected': False, 'text': '<p>The accepted answer is good.\nTo extend on the last part:</p>\n\n<blockquote>\n  <p>Note that encodeURIComponent does not escape the \' character. A common\n  bug is to use it to create html attributes such as href=\'MyUrl\', which\n  could suffer an injection bug. If you are constructing html from\n  strings, either use " instead of \' for attribute quotes, or add an\n  extra layer of encoding (\' can be encoded as %27).</p>\n</blockquote>\n\n<p>If you want to be on the safe side, <a href="https://en.wikipedia.org/wiki/Percent-encoding#Percent-encoding_unreserved_characters" rel="nofollow noreferrer">percent encoding unreserved characters</a> should be encoded as well. </p>\n\n<p>You can use this method to escape them (source <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent" rel="nofollow noreferrer">Mozilla</a>)</p>\n\n<pre><code>function fixedEncodeURIComponent(str) {\n  return encodeURIComponent(str).replace(/[!\'()*]/g, function(c) {\n    return \'%\' + c.charCodeAt(0).toString(16);\n  });\n}\n\n// fixedEncodeURIComponent("\'") --&gt; "%27"\n</code></pre>\n'}, {'answer_id': 48697555, 'author': 'ryanpcmcquen', 'author_id': 2662028, 'author_profile': 'https://Stackoverflow.com/users/2662028', 'pm_score': 2, 'selected': False, 'text': '<p>Modern rewrite of @johann-echavarria\'s answer:</p>\n\n<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">\r\n<div class="snippet-code">\r\n<pre class="snippet-code-js lang-js prettyprint-override"><code>console.log(\r\n    Array(256)\r\n        .fill()\r\n        .map((ignore, i) =&gt; String.fromCharCode(i))\r\n        .filter(\r\n            (char) =&gt;\r\n                encodeURI(char) !== encodeURIComponent(char)\r\n                    ? {\r\n                          character: char,\r\n                          encodeURI: encodeURI(char),\r\n                          encodeURIComponent: encodeURIComponent(char)\r\n                      }\r\n                    : false\r\n        )\r\n)</code></pre>\r\n</div>\r\n</div>\r\n</p>\n\n<p>Or if you can use a table, replace <code>console.log</code> with <code>console.table</code> (for the prettier output).</p>\n'}, {'answer_id': 54630088, 'author': 'akinuri', 'author_id': 2202732, 'author_profile': 'https://Stackoverflow.com/users/2202732', 'pm_score': 2, 'selected': False, 'text': '<p>Inspired by <a href="https://stackoverflow.com/questions/75980/when-are-you-supposed-to-use-escape-instead-of-encodeuri-encodeuricomponent/23842171#23842171">Johann\'s table</a>, I\'ve decided to extend the table. I wanted to see which ASCII characters get encoded.</p>\n\n<p><a href="https://i.stack.imgur.com/gjKxF.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gjKxF.png" alt="screenshot of console.table"></a></p>\n\n<p><div class="snippet" data-lang="js" data-hide="true" data-console="true" data-babel="false">\r\n<div class="snippet-code snippet-currently-hidden">\r\n<pre class="snippet-code-js lang-js prettyprint-override"><code>var ascii = " !\\"#$%&amp;\'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~";\r\n\r\nvar encoded = [];\r\n\r\nascii.split("").forEach(function (char) {\r\n    var obj = { char };\r\n    if (char != encodeURI(char))\r\n        obj.encodeURI = encodeURI(char);\r\n    if (char != encodeURIComponent(char))\r\n        obj.encodeURIComponent = encodeURIComponent(char);\r\n    if (obj.encodeURI || obj.encodeURIComponent)\r\n        encoded.push(obj);\r\n});\r\n\r\nconsole.table(encoded);</code></pre>\r\n</div>\r\n</div>\r\n</p>\n\n<p>Table shows only the encoded characters. Empty cells mean that the original and the encoded characters are the same.</p>\n\n<hr>\n\n<p>Just to be extra, I\'m adding another table for <a href="http://php.net/manual/en/function.urlencode.php" rel="nofollow noreferrer"><code>urlencode()</code></a> vs <a href="http://php.net/manual/en/function.rawurlencode.php" rel="nofollow noreferrer"><code>rawurlencode()</code></a>. The only difference seems to be the encoding of space character.</p>\n\n<p><a href="https://i.stack.imgur.com/gJnmU.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/gJnmU.png" alt="screenshot of console.table"></a></p>\n\n<pre><code>&lt;script&gt;\n&lt;?php\n$ascii = str_split(" !\\"#$%&amp;\'()*+,-./0123456789:;&lt;=&gt;?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\\\\]^_`abcdefghijklmnopqrstuvwxyz{|}~", 1);\n$encoded = [];\nforeach ($ascii as $char) {\n    $obj = ["char" =&gt; $char];\n    if ($char != urlencode($char))\n        $obj["urlencode"] = urlencode($char);\n    if ($char != rawurlencode($char))\n        $obj["rawurlencode"] = rawurlencode($char);\n    if (isset($obj["rawurlencode"]) || isset($obj["rawurlencode"]))\n        $encoded[] = $obj;\n}\necho "var encoded = " . json_encode($encoded) . ";";\n?&gt;\nconsole.table(encoded);\n&lt;/script&gt;\n</code></pre>\n'}, {'answer_id': 62436236, 'author': 'HoldOffHunger', 'author_id': 2430549, 'author_profile': 'https://Stackoverflow.com/users/2430549', 'pm_score': 3, 'selected': False, 'text': '<p>Just try <code>encodeURI()</code> and <code>encodeURIComponent()</code> yourself...</p>\n<p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">\r\n<div class="snippet-code">\r\n<pre class="snippet-code-js lang-js prettyprint-override"><code>console.log(encodeURIComponent(\'@#$%^&amp;*\'));</code></pre>\r\n</div>\r\n</div>\r\n</p>\n<p>Input: <code>@#$%^&amp;*</code>.  Output: <code>%40%23%24%25%5E%26*</code>.  So, wait, what happened to <code>*</code>?  Why wasn\'t this converted?  It could definitely cause problems if you tried to do <code>linux command &quot;$string&quot;</code>.  TLDR: You actually want <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent" rel="nofollow noreferrer"><code>fixedEncodeURIComponent()</code></a> and <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI" rel="nofollow noreferrer"><code>fixedEncodeURI()</code></a>.  Long-story...</p>\n<p><em><strong>When to use <code>encodeURI()</code>?</strong></em>  Never.  <code>encodeURI()</code> fails to adhere to RFC3986 with regard to bracket-encoding.  Use <code>fixedEncodeURI()</code>, as defined and further explained at the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURI" rel="nofollow noreferrer"><strong>MDN encodeURI() Documentation</strong></a>...</p>\n<blockquote>\n<pre><code>function fixedEncodeURI(str) {\n   return encodeURI(str).replace(/%5B/g, \'[\').replace(/%5D/g, \']\');\n}\n</code></pre>\n</blockquote>\n<p><em><strong>When to use <code>encodeURIComponent()</code>?</strong></em>  Never.  <code>encodeURIComponent()</code> fails to adhere to RFC3986 with regard to encoding: <code>!\'()*</code>.  Use <code>fixedEncodeURIComponent()</code>, as defined and further explained at the <a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/encodeURIComponent" rel="nofollow noreferrer"><strong>MDN encodeURIComponent() Documentation</strong></a>...</p>\n<blockquote>\n<pre><code>function fixedEncodeURIComponent(str) {\n return encodeURIComponent(str).replace(/[!\'()*]/g, function(c) {\n   return \'%\' + c.charCodeAt(0).toString(16);\n });\n}\n</code></pre>\n</blockquote>\n<p>Then you can use <code>fixedEncodeURI()</code> to encode a single URL piece, whereas <code>fixedEncodeURIComponent()</code> will encode URL pieces and connectors; or, simply, <code>fixedEncodeURI()</code> will not encode <code>+@?=:#;,$&amp;</code> (as <code>&amp;</code> and <code>+</code> are common URL operators), but <code>fixedEncodeURIComponent()</code> will.</p>\n'}]
['https://Stackoverflow.com/questions/75980', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/1341/']