Skip to content

Commit

Permalink
Clarify what gets percent-encoded in data URLs
Browse files Browse the repository at this point in the history
Also fixes #2840
  • Loading branch information
sideshowbarker committed Mar 4, 2021
1 parent 6bb5b53 commit b268f5a
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions files/en-us/web/http/basics_of_http/data_uris/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -25,13 +25,15 @@ <h2 id="Syntax">Syntax</h2>

<p>The <code>mediatype</code> is a <a href="/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types">MIME type</a> string, such as <code>'image/jpeg'</code> for a JPEG image file. If omitted, defaults to <code>text/plain;charset=US-ASCII</code></p>

<p>If the data is textual, you can embed the text (using the appropriate entities or escapes based on the enclosing document's type). Otherwise, you can specify <code>base64</code> to embed base64-encoded binary data. You can find more info on MIME types <a href="/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types">here</a> and <a href="/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Complete_list_of_MIME_types">here</a>.</p>
<p>If the data contains <a href="https://tools.ietf.org/html/rfc3986#section-2.2">characters defined in RFC 3986 as reserved characters</a>, space characters, newline characters, or other non-printing characters, those characters must be <a href="/en-US/docs/Glossary/percent-encoding">percent-encoded</a> (<em>aka</em> “URL-encoded”).</p>

<p>If the data is textual, you can embed the text (using the appropriate entities or escapes based on the enclosing document's type). Otherwise, you can specify <code>base64</code> to embed base64-encoded binary data. You can find more info on MIME types <a href="/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types">here</a> and <a href="/en-US/docs/Web/HTTP/Basics_of_HTTP/MIME_types/Common_types">here</a>.</p>

<p>A few examples:</p>

<dl>
<dt><code>data:,Hello%2C%20World!</code></dt>
<dd>Simple text/plain data. Note the use of <a href="/en-US/docs/Glossary/percent-encoding">percent-encoding</a> (URL-encoding) for the quote and space characters. Also, for CSV data (MIME type "text/csv"), percent-encoding is needed to preserve the line endings that delimit rows of the spreadsheet.</dd>
<dd>The text/plain data <code>Hello, World!</code>. Note how the comma is <a href="/en-US/docs/Glossary/percent-encoding">percent-encoded</a> as <code>%2C</code>, and the space character as <code>%20</code>.</dd>
<dt><code>data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==</code></dt>
<dd>base64-encoded version of the above</dd>
<dt><code>data:text/html,%3Ch1%3EHello%2C%20World!%3C%2Fh1%3E</code></dt>
Expand Down

0 comments on commit b268f5a

Please sign in to comment.