Skip to content

Commit

Permalink
Make get, decode, and split handle edge cases correctly
Browse files Browse the repository at this point in the history
Correct handling of the empty string input and input with a trailing comma.

Fixes #1768.
  • Loading branch information
annevk authored Aug 30, 2024
1 parent 4cb3cf2 commit 3153e5e
Showing 1 changed file with 29 additions and 25 deletions.
54 changes: 29 additions & 25 deletions fetch.bs
Original file line number Diff line number Diff line change
Expand Up @@ -698,6 +698,19 @@ A: nosniff
B: sniff
A:
</code></pre>
<tr>
<td>
<pre><code class=lang-http>
A:
B: sniff
</code></pre>
<td>« "" »
<tr>
<td>
<pre><code class=lang-http>
B: sniff
</code></pre>
<td>null
<tr>
<td>
<pre><code class=lang-http>A: text/html;", x/x</code></pre>
Expand Down Expand Up @@ -763,12 +776,12 @@ a <a for=/>header value</a> <var>value</var>, run these steps. They return a <a
<li><p>Let <var>position</var> be a <a for=string>position variable</a> for <var>input</var>,
initially pointing at the start of <var>input</var>.

<li><p>Let <var>values</var> be a <a for=/>list</a> of <a for=/>strings</a>, initially empty.
<li><p>Let <var>values</var> be a <a for=/>list</a> of <a for=/>strings</a>, initially « ».

<li><p>Let <var>temporaryValue</var> be the empty string.

<li>
<p>While <var>position</var> is not past the end of <var>input</var>:
<p>While true:

<ol>
<li>
Expand All @@ -778,40 +791,30 @@ a <a for=/>header value</a> <var>value</var>, run these steps. They return a <a
<p class=note>The result might be the empty string.

<li>
<p>If <var>position</var> is not past the end of <var>input</var>, then:
<p>If <var>position</var> is not past the end of <var>input</var> and the
<a for=/>code point</a> at <var>position</var> within <var>input</var> is U+0022 ("):

<ol>
<li>
<p>If the <a for=/>code point</a> at <var>position</var> within <var>input</var> is
U+0022 ("), then:

<ol>
<li><p>Append the result of <a>collecting an HTTP quoted string</a> from <var>input</var>,
given <var>position</var>, to <var>temporaryValue</var>.
<li><p>Append the result of <a>collecting an HTTP quoted string</a> from <var>input</var>,
given <var>position</var>, to <var>temporaryValue</var>.

<li>If <var>position</var> is not past the end of <var>input</var>, then
<a for=iteration>continue</a>.
</ol>

<li>
<p>Otherwise:

<ol>
<li><p>Assert: the <a for=/>code point</a> at <var>position</var> within <var>input</var> is
U+002C (,).

<li><p>Advance <var>position</var> by 1.
</ol>
<li>If <var>position</var> is not past the end of <var>input</var>, then
<a for=iteration>continue</a>.
</ol>

<li><p>Remove all <a>HTTP tab or space</a> from the start and end of <var>temporaryValue</var>.

<li><p><a for=list>Append</a> <var>temporaryValue</var> to <var>values</var>.

<li><p>Set <var>temporaryValue</var> to the empty string.
</ol>

<li><p>Return <var>values</var>.
<li><p>If <var>position</var> is past the end of <var>input</var>, then return <var>values</var>.

<li><p><a for=/>Assert</a>: the <a for=/>code point</a> at <var>position</var> within
<var>input</var> is U+002C (,).

<li><p>Advance <var>position</var> by 1.
</ol>
</ol>

<p class=note>Except for blessed call sites, the algorithm directly above is not to be invoked
Expand Down Expand Up @@ -9040,6 +9043,7 @@ Brad Porter,
Bryan Smith,
Caitlin Potter,
Cameron McCormack,
Carlo Cannas,
白丞祐 (Cheng-You Bai)<!-- CYBAI; GitHub -->,
Chirag S Kumar<!-- fictionistique; GitHub -->,
Chris Needham,
Expand Down

0 comments on commit 3153e5e

Please sign in to comment.