Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<h1>escape()</h1> <p>Don't use it! <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> <blockquote> <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> ... Programmers should not use or assume the existence of these features and behaviours when writing new ECMAScript code....</p> </blockquote> <p>Behaviour:</p> <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> <p>Special characters are encoded with the exception of: @*_+-./</p> <p>The hexadecimal form for characters, whose code unit value is 0xFF or less, is a two-digit escape sequence: <code>%xx</code>.</p> <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://tools.ietf.org/html/rfc3986#section-3.4" rel="noreferrer">RFC3986</a>):</p> <pre><code>query = *( pchar / "/" / "?" ) pchar = unreserved / pct-encoded / sub-delims / ":" / "@" unreserved = ALPHA / DIGIT / "-" / "." / "_" / "~" pct-encoded = "%" HEXDIG HEXDIG sub-delims = "!" / "$" / "&amp;" / "'" / "(" / ")" / "*" / "+" / "," / ";" / "=" </code></pre> <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> <h1>encodeURI()</h1> <p>Use encodeURI when you want a working URL. Make this call:</p> <pre><code>encodeURI("http://www.example.org/a file with spaces.html") </code></pre> <p>to get:</p> <pre><code>http://www.example.org/a%20file%20with%20spaces.html </code></pre> <p>Don't call encodeURIComponent since it would destroy the URL and return</p> <pre><code>http%3A%2F%2Fwww.example.org%2Fa%20file%20with%20spaces.html </code></pre> <h1>encodeURIComponent()</h1> <p>Use encodeURIComponent when you want to encode the value of a URL parameter.</p> <pre><code>var p1 = encodeURIComponent("http://example.org/?a=12&amp;b=55") </code></pre> <p>Then you may create the URL you need:</p> <pre><code>var url = "http://example.net/?param1=" + p1 + "&amp;param2=99"; </code></pre> <p>And you will get this complete URL:</p> <p><code>http://example.net/?param1=http%3A%2F%2Fexample.org%2F%Ffa%3D12%26b%3D55&amp;param2=99</code></p> <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>"</code> instead of <code>'</code> for attribute quotes, or add an extra layer of encoding (<code>'</code> can be encoded as %27).</p> <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>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload