Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adjust rules for parsing dimension values #4747

Merged
merged 3 commits into from
Jul 3, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
81 changes: 45 additions & 36 deletions source
Original file line number Diff line number Diff line change
Expand Up @@ -4887,10 +4887,11 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute

<p>The <dfn>rules for parsing dimension values</dfn> are as given in the following algorithm. When
invoked, the steps must be followed in the order given, aborting at the first step that returns a
value. This algorithm will return either a number greater than or equal to 0.0, or an error; if a
value. This algorithm will return either a number greater than or equal to 0.0, or failure; if a
number is returned, then it is further categorized as either a percentage or a length.</p>

<ol>
<li><p>Let <var>value</var> be null.</p></li>

<li><p>Let <var>input</var> be the string being parsed.</p></li>

Expand All @@ -4900,66 +4901,74 @@ a.setAttribute('href', 'https://example.com/'); // change the content attribute
<li><p><span>Skip ASCII whitespace</span> within <var>input</var> given
<var>position</var>.</p></li>

<li><p>If <var>position</var> is past the end of <var>input</var>, return an error.</p></li>

<li><p>If the character indicated by <var>position</var> is a U+002B PLUS SIGN character (+),
advance <var>position</var> to the next character.</li>

<li><p>If <var>position</var> is past the end of <var>input</var>, return an error.</p></li>

<li><p>If the character indicated by <var>position</var> is not an <span data-x="ASCII
digits">ASCII digit</span>, then return an error.</p></li>
<li><p>If <var>position</var> is past the end of <var>input</var>, return failure.</p></li>

<!-- Ok. At this point we know we have a number. It might have trailing garbage which we'll
ignore, but it's a number, and we won't return an error. -->
<li>
<p>If the character indicated by <var>position</var> is an <span data-x="ASCII digits">ASCII
digit</span>, then:

<li><p><span>Collect a sequence of code points</span> that are <span>ASCII digits</span> from
<var>input</var> given <var>position</var>, and interpret the resulting sequence as a base-ten
integer. Let <var>value</var> be that number.</li>
<ol>
<li><p><span>Collect a sequence of code points</span> that are <span>ASCII digits</span> from
<var>input</var> given <var>position</var>, and interpret the resulting sequence as a base-ten
integer. Set <var>value</var> to that number.</p></li>

<li><p>If <var>position</var> is past the end of <var>input</var>, return <var>value</var> as a
length.</p></li>
<li><p>If <var>position</var> is past the end of <var>input</var>, return <var>value</var> as a
length.</p></li>
</ol>

<li>

<p>If the character indicated by <var>position</var> is a U+002E FULL STOP character (.):</p>
<p>If the character indicated by <var>position</var> is U+002E (.), then:</p>

<ol>

<li><p>Advance <var>position</var> to the next character.</p></li>

<li><p>If <var>position</var> is past the end of <var>input</var>, or if the character
indicated by <var>position</var> is not an <span data-x="ASCII digits">ASCII digit</span>, then
return <var>value</var> as a length.</li>
<li><p>If <var>position</var> is past the end of <var>input</var> or if the character indicated
by <var>position</var> is not an <span data-x="ASCII digits">ASCII digit</span>, then return
the <span>current dimension value</span> with <var>value</var>, <var>input</var>, and
<var>position</var>.</p></li>

<li><p>If <var>value</var> is null, then set <var>value</var> to 0.</p></li>

<li><p>Let <var>divisor</var> have the value 1.</p></li>

<li><p><i>Fraction loop</i>: Multiply <var>divisor</var> by ten.</p></li>
<li>
<p>While true:</p>

<li>Add the value of the character indicated by <var>position</var>, interpreted as a base-ten
digit (0..9) and divided by <var>divisor</var>, to <var>value</var>.</li>
<ol>
<li><p>Multiply <var>divisor</var> by ten.</p></li>

<li><p>Advance <var>position</var> to the next character.</p></li>
<li><p>Add the value of the character indicated by <var>position</var>, interpreted as a
base-ten digit (0..9) and divided by <var>divisor</var>, to <var>value</var>.</p></li>

<li><p>If <var>position</var> is past the end of <var>input</var>, then return <var>value</var>
as a length.</li>
<li><p>Advance <var>position</var> to the next character.</p></li>

<li><p>If the character indicated by <var>position</var> is an <span data-x="ASCII
digits">ASCII digit</span>, return to the step labeled <i>fraction loop</i> in these
substeps.</p></li>
<li><p>If <var>position</var> is past the end of <var>input</var>, then return
<var>value</var> as a length.</p></li>

<li><p>If the character indicated by <var>position</var> is not an <span data-x="ASCII
digits">ASCII digit</span>, then <span>break</span>.</p></li>
</ol>
</li>
</ol>

</li>

<li><p>Return the <span>current dimension value</span> with <var>value</var>, <var>input</var>,
and <var>position</var>.</p></li>
</ol>

<p>The <dfn>current dimension value</dfn>, given <var>value</var>, <var>input</var>, and
<var>position</var>, is determined as follows:</p>

<ol>
<li><p>If <var>value</var> is null, then return failure.</p></li>

<li><p>If <var>position</var> is past the end of <var>input</var>, return <var>value</var> as a
length.</p></li>

<li><p>If the character indicated by <var>position</var> is a U+0025 PERCENT SIGN character (%),
return <var>value</var> as a percentage.</p></li>
<li><p>If the character indicated by <var>position</var> is U+0025 (%), then return
<var>value</var> as a percentage.</p></li>

<li><p>Return <var>value</var> as a length.</p></li>

</ol>

<h5>Non-zero percentages and lengths</h5>
Expand Down