<?xml version="1.0" encoding="UTF-8" standalone="yes" ?>
<!DOCTYPE bugzilla SYSTEM "https://www.w3.org/Bugs/Public/page.cgi?id=bugzilla.dtd">

<bugzilla version="5.0.4"
          urlbase="https://www.w3.org/Bugs/Public/"
          
          maintainer="sysbot+bugzilla@w3.org"
>

    <bug>
          <bug_id>28148</bug_id>
          
          <creation_ts>2015-03-05 21:35:59 +0000</creation_ts>
          <short_desc>Improve parsing of numbers for coords attribute</short_desc>
          <delta_ts>2016-04-29 14:56:35 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>HTML WG</product>
          <component>HTML5 spec</component>
          <version>unspecified</version>
          <rep_platform>PC</rep_platform>
          <op_sys>Windows NT</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>MOVED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard>whatwg-resolved</status_whiteboard>
          <keywords></keywords>
          <priority>P1</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>---</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Travis Leithead [MSFT]">travil</reporter>
          <assigned_to name="This bug has no owner yet - up for the taking">dave.null</assigned_to>
          <cc>arronei</cc>
    
    <cc>bzbarsky</cc>
    
    <cc>mike</cc>
    
    <cc>public-html-admin</cc>
    
    <cc>public-html-wg-issue-tracking</cc>
    
    <cc>travil</cc>
    
    <cc>zcorpan</cc>
          
          <qa_contact name="HTML WG Bugzilla archive list">public-html-bugzilla</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>118371</commentid>
    <comment_count>0</comment_count>
    <who name="Travis Leithead [MSFT]">travil</who>
    <bug_when>2015-03-05 21:35:59 +0000</bug_when>
    <thetext>For floating point arguments between 0 and 1 without a leading 0, the floating point value simply drops the decimal.  So for example, &lt;area shape=&quot;rect&quot; coords=&quot;.100, .100, 101, 101&quot;&gt; will result in a rect at &quot;100, 100, 101, 101&quot; rather than something more expected like &quot;0, 0, 101, 101&quot;.

On the other hand, there&apos;s no reason why the coords attribute shouldn&apos;t accept a list of floating point values rather than integers, which could also circumvent the problem.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>118377</commentid>
    <comment_count>1</comment_count>
    <who name="Boris Zbarsky">bzbarsky</who>
    <bug_when>2015-03-06 02:30:24 +0000</bug_when>
    <thetext>&gt; For floating point arguments between 0 and 1 without a leading 0, the floating
&gt; point value simply drops the decimal.

Do UAs implement that?  Because I don&apos;t think Gecko does: we seem to chunk up the list on whitespace+commas and then just atoi the things in between, so .100 turns into 0.

&gt; there&apos;s no reason why the coords attribute shouldn&apos;t accept a list of floating
&gt; point values

Except for possible compat issues, right?  Again, would be good to know what actual UAs do here.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>118382</commentid>
    <comment_count>2</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2015-03-06 08:16:24 +0000</bug_when>
    <thetext>The spec is intended to match IE exactly for the ASCII range. Presto implemented the spec.

It seems Blink and WebKit parses more like Gecko.

http://software.hixie.ch/utilities/js/live-dom-viewer/saved/3439

Also see https://lists.w3.org/Archives/Public/public-html/2009Jan/0086.html for earlier compat analysis.

I suppose we could change the spec to be more like Gecko/Blink/WebKit, but at least when I studied this for Presto&apos;s implementation it seemed like IE&apos;s parsing worked better for actual Web content.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>118995</commentid>
    <comment_count>3</comment_count>
    <who name="Travis Leithead [MSFT]">travil</who>
    <bug_when>2015-03-27 20:43:22 +0000</bug_when>
    <thetext>Only IE has this behavior (and is thus compliant with the wording in the spec), test page: http://jsfiddle.net/6mr5s457/

Chrome/FF’s behavior is noncompliant on two accounts.  One, they don’t implement the algorithm as specified or they’d have the same behavior as IE.  Two, they are accepting floating point values even though the spec says to use integer parsing.

Even assuming we change the spec to allow coords to accept floating point values (which we should), it’s strange that Chrome/FF don’t do any normalization in this parsing – e.g. &quot;.100&quot; stays as such, and isn’t normalized to &quot;.1&quot; or &quot;0.1&quot;.

So I recommend a few things:
1. Fix the integer list parsing algorithm so it doesn’t just drop leading decimals (instead these should become 0, for both positive and negative, in order to match the truncating behavior that other floating point numbers get in this algorithm):
http://www.w3.org/TR/html5/infrastructure.html#rules-for-parsing-a-list-of-integers

2. Rephrase coords to allow a valid list of floating point numbers.  I don’t think there’s an existing algorithm for this (there’s an algorithm for floating point numbers, and a list of integers, but not a list of floating point numbers):
http://www.w3.org/TR/html5/embedded-content-0.html#attr-area-coords

3. I didn’t look very hard at the floating point number parsing algorithm, but if it doesn’t specify normalization (e.g. trim trailing 0’s and enforce a digit before the decimal) that might be worthwhile to discuss.
http://www.w3.org/TR/html5/infrastructure.html#rules-for-parsing-floating-point-number-values

4. There’s a lot of ambiguity around coords whether the requirements are for the UA or the author.  Would be good to clarify so these are actually testable.
http://www.w3.org/TR/html5/embedded-content-0.html#attr-area-shape-circle</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>119081</commentid>
    <comment_count>4</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2015-03-30 20:37:05 +0000</bug_when>
    <thetext>(In reply to Travis Leithead [MSFT] from comment #3)
&gt; Only IE has this behavior (and is thus compliant with the wording in the
&gt; spec), test page: http://jsfiddle.net/6mr5s457/
&gt; 
&gt; Chrome/FF’s behavior is noncompliant on two accounts.  One, they don’t
&gt; implement the algorithm as specified or they’d have the same behavior as IE.
&gt; Two, they are accepting floating point values even though the spec says to
&gt; use integer parsing.
&gt; 
&gt; Even assuming we change the spec to allow coords to accept floating point
&gt; values (which we should), it’s strange that Chrome/FF don’t do any
&gt; normalization in this parsing – e.g. &quot;.100&quot; stays as such, and isn’t
&gt; normalized to &quot;.1&quot; or &quot;0.1&quot;.

Normalized where? The parsed value is not serialized anywhere per spec. .coords just reflects as a plain DOMString, i.e. same as getAttribute.

&gt; So I recommend a few things:
&gt; 1. Fix the integer list parsing algorithm so it doesn’t just drop leading
&gt; decimals (instead these should become 0, for both positive and negative, in
&gt; order to match the truncating behavior that other floating point numbers get
&gt; in this algorithm):
&gt; http://www.w3.org/TR/html5/infrastructure.html#rules-for-parsing-a-list-of-
&gt; integers

OK.

&gt; 2. Rephrase coords to allow a valid list of floating point numbers.  I don’t
&gt; think there’s an existing algorithm for this (there’s an algorithm for
&gt; floating point numbers, and a list of integers, but not a list of floating
&gt; point numbers):
&gt; http://www.w3.org/TR/html5/embedded-content-0.html#attr-area-coords

Should parsing of this list try to be compatible with IE&apos;s coords parsing (modulo the necessary differences to support floats), or Gecko/Blink? (I guess we could re-check the web compat situation.)

&gt; 3. I didn’t look very hard at the floating point number parsing algorithm,
&gt; but if it doesn’t specify normalization (e.g. trim trailing 0’s and enforce
&gt; a digit before the decimal) that might be worthwhile to discuss.
&gt; http://www.w3.org/TR/html5/infrastructure.html#rules-for-parsing-floating-
&gt; point-number-values

Again normalization implies serialization...

&gt; 4. There’s a lot of ambiguity around coords whether the requirements are for
&gt; the UA or the author.  Would be good to clarify so these are actually
&gt; testable.
&gt; http://www.w3.org/TR/html5/embedded-content-0.html#attr-area-shape-circle

I don&apos;t see what&apos;s ambiguous? See https://html.spec.whatwg.org/multipage/infrastructure.html#conformance-classes</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>121053</commentid>
    <comment_count>5</comment_count>
    <who name="Michael[tm] Smith">mike</who>
    <bug_when>2015-06-16 10:25:14 +0000</bug_when>
    <thetext>Making this a higher priority to actively seek more feedback on from implementers and webdevs.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>121054</commentid>
    <comment_count>6</comment_count>
    <who name="Michael[tm] Smith">mike</who>
    <bug_when>2015-06-16 10:26:22 +0000</bug_when>
    <thetext>Noting that this is blocked on waiting for more info from Travis.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>124398</commentid>
    <comment_count>7</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2015-12-09 14:01:29 +0000</bug_when>
    <thetext>Travis, what does Edge do here now?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>124403</commentid>
    <comment_count>8</comment_count>
    <who name="Travis Leithead [MSFT]">travil</who>
    <bug_when>2015-12-09 18:35:55 +0000</bug_when>
    <thetext>(In reply to Simon Pieters from comment #7)
&gt; Travis, what does Edge do here now?

Just tested in my latest Edge build, and its behavior is unchanged from comment #1. I&apos;m not a fan of the behavior. Seems like Edge should change to match Gecko/Chrome</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>124581</commentid>
    <comment_count>9</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2016-01-13 22:58:26 +0000</bug_when>
    <thetext>Blink&apos;s coords parsing is at https://code.google.com/p/chromium/codesearch#chromium/src/third_party/WebKit/Source/platform/Length.cpp&amp;sq=package:chromium&amp;type=cs&amp;l=71&amp;rcl=1452688339

it seems to replace all characters other than [0-9\.-] with space and then split on spaces, e.g. coords=&quot;0x0x,x,10 10&quot; is parsed the same as coords=&quot;0,0,10,10&quot;.

Gecko&apos;s coords parsing is described in https://lists.w3.org/Archives/Public/public-html/2009Jan/0086.html . Jonas notes that they have some bugs filed e.g. for not ignoring a leading comma.

In webdevdata I find some interesting cases but in particular this from babyneo.de:

&lt;map name=&apos;header1&apos;&gt;
  &lt;area shape=&quot;rect&quot; alt=&quot;Zur Startseite&quot; coords=&quot;=&apos;69,8,153,86&apos; &quot; href=&quot;http://www.babyneo.de/&quot; title=&quot;Zur Startseite&quot; &gt;
  &lt;area shape=&quot;rect&quot; alt=&quot;Zur Startseite&quot; coords=&quot;=&apos;5,85,223,140&apos; &quot; href=&quot;http://www.babyneo.de/&quot; title=&quot;Zur Startseite&quot; &gt;
  &lt;area shape=&quot;rect&quot; alt=&quot;Warenkorb anzeigen&quot; coords=&quot;=&apos;824,49,950,74&apos;  &quot; href=&quot;http://www.babyneo.de/shopping_cart.php&quot; title=&quot;Warenkorb anzeigen&quot; &gt;
&lt;/map&gt;

In Gecko the first value of each get parsed into 0, but IE/Blink/WebKit/Presto parse into the given number ignoring the leading garbage, which appears to more closely match what was intended.

I didn&apos;t see any using ; in coords. But some with consecutive commas or leading/trailing garbage.

I implemented the spec&apos;s algorithm in JS and wrote a new different implementation [1], and compared the output of real-world coords values [2], and checked the result against the some of the actual pages to see what would be an improvement in terms of web compat. I believe it&apos;s somewhat of a mix of what all browsers do give the best results, and I ended up with the following:

function newCoords(input) {
  var numbers = [];
  // split
  var tokens = input.split(/[\s,]+/);
  // for each token in tokens
  for (var i = 0; i &lt; tokens.length; ++i) {
    var token = tokens[i];
    // replace garbage with spaces
    token = token.replace(/[^\d\.-]/g, &apos; &apos;);
    // parse as float; add to numbers
    numbers.push(parseFloat(token, 10) || 0);
  }
  // return numbers
  return numbers;
}

[1] https://gist.github.com/zcorpan/baa697e081a3e1aa5da0
[2] https://gist.github.com/zcorpan/37050c2b556c5d0b5b88</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>124584</commentid>
    <comment_count>10</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2016-01-14 08:05:23 +0000</bug_when>
    <thetext>Forgot about ignoring leading commas:

function newCoords(input) {
  var numbers = [];
  // trim leading separators
  input = input.replace(/^[\s,]+/, &apos;&apos;);
  // split
  var tokens = input.split(/[\s,]+/);
  // for each token in tokens
  for (var i = 0; i &lt; tokens.length; ++i) {
    var token = tokens[i];
    // replace garbage with spaces
    token = token.replace(/[^\d\.-]/g, &apos; &apos;);
    // parse as float; add to numbers
    numbers.push(parseFloat(token, 10) || 0);
  }
  // return numbers
  return numbers;
}

\s here should be HTML&apos;s &quot;space characters&quot;.

I could go either way with ; as separator.

Maybe also support scientific notation? It would be easy to trim only leading garbage in each token, and let HTML&apos;s float parser deal with trailing garbage.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>124585</commentid>
    <comment_count>11</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2016-01-14 09:28:38 +0000</bug_when>
    <thetext>https://github.com/whatwg/html/pull/514</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>124602</commentid>
    <comment_count>12</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2016-01-15 14:01:08 +0000</bug_when>
    <thetext>Travis, I filed https://connect.microsoft.com/IE/feedbackdetail/view/2245506/implement-area-coords-parsing-per-spec FYI</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126216</commentid>
    <comment_count>13</comment_count>
    <who name="Arron Eicholz">arronei</who>
    <bug_when>2016-04-27 18:25:13 +0000</bug_when>
    <thetext>HTML5.1 Bugzilla Bug Triage: Fixed in the latest draft

If this resolution is not satisfactory, please copy the relevant bug details/proposal into a new issue at the W3C HTML5 Issue tracker: https://github.com/w3c/html/issues/new where it will be re-triaged. Thanks!</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126302</commentid>
    <comment_count>14</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2016-04-29 13:20:54 +0000</bug_when>
    <thetext>Can you point to the commit?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>126304</commentid>
    <comment_count>15</comment_count>
    <who name="Travis Leithead [MSFT]">travil</who>
    <bug_when>2016-04-29 14:56:35 +0000</bug_when>
    <thetext>Apologies--double checked, and this does **not** appear to be in the latest draft. Filed: https://github.com/w3c/html/issues/319 to track the integration.

Changed resolution to MOVED.</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>