<?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>26446</bug_id>
          
          <creation_ts>2014-07-28 18:30:50 +0000</creation_ts>
          <short_desc>A URL&apos;s port should be an (optional) number, not a string</short_desc>
          <delta_ts>2015-08-14 14:38:11 +0000</delta_ts>
          <reporter_accessible>1</reporter_accessible>
          <cclist_accessible>1</cclist_accessible>
          <classification_id>1</classification_id>
          <classification>Unclassified</classification>
          <product>WHATWG</product>
          <component>URL</component>
          <version>unspecified</version>
          <rep_platform>All</rep_platform>
          <op_sys>All</op_sys>
          <bug_status>RESOLVED</bug_status>
          <resolution>FIXED</resolution>
          
          
          <bug_file_loc></bug_file_loc>
          <status_whiteboard></status_whiteboard>
          <keywords></keywords>
          <priority>P2</priority>
          <bug_severity>normal</bug_severity>
          <target_milestone>Unsorted</target_milestone>
          
          
          <everconfirmed>1</everconfirmed>
          <reporter name="Simon Sapin">simon.sapin</reporter>
          <assigned_to name="Anne">annevk</assigned_to>
          <cc>d</cc>
    
    <cc>mike</cc>
    
    <cc>rubys</cc>
    
    <cc>zcorpan</cc>
          
          <qa_contact>sideshowbarker+urlspec</qa_contact>

      

      

      

          <comment_sort_order>oldest_to_newest</comment_sort_order>  
          <long_desc isprivate="0" >
    <commentid>109400</commentid>
    <comment_count>0</comment_count>
    <who name="Simon Sapin">simon.sapin</who>
    <bug_when>2014-07-28 18:30:50 +0000</bug_when>
    <thetext>Currently, the spec defines an URL’s port as string of digits of arbitrary length. However, implementations seem to be storing it as a number with limited range, internally.

Test case:

data:text/html,&lt;a href=&quot;http://example.com:65535&quot;&gt;&lt;/a&gt;&lt;script&gt;document.write(document.querySelector(&apos;a&apos;).port)&lt;/script&gt;

This works everywhere as expected and displays &quot;65535&quot;.

When changing 65535 to higher numbers:

For 65536 (2^16) or above, Chromium displays &quot;0&quot;.
For 65536 (2^16) or above, IE displays the empty string.
For 2147483648 (2^31) or above, Firefox displays the empty string.

I suggest changing the URL parser to interpret the digits of the port as a decimal number, return failure if it’s 65536 or more (i.e., would overflow a 16 bit unsigned integer), and change &quot;A URL&apos;s port&quot; in the model to be either null or a 16 bit number.

Note that port numbers are 16 bit (from 0 to 65535) in both TCP and UDP (though only TCP is really relevant here.)</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>109471</commentid>
    <comment_count>1</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2014-07-29 09:02:42 +0000</bug_when>
    <thetext>This seemed like a place where we could follow the RFCs going forward. Did you check with Necko peers whether they want to pursue convergence with Chrome and IE here?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>119514</commentid>
    <comment_count>2</comment_count>
    <who name="Domenic Denicola">d</who>
    <bug_when>2015-04-15 06:21:45 +0000</bug_when>
    <thetext>io.js is looking for guidance on what their port setter should do, and perhaps separately what their port parser should do. See https://github.com/iojs/io.js/pull/933#issuecomment-93215122

It sounds like the plan is empty string? Or is it &quot;0&quot;? Should port return a JS number or a JS string?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>119518</commentid>
    <comment_count>3</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2015-04-15 07:06:20 +0000</bug_when>
    <thetext>URL.prototype.port&apos;s get will return a string and its set will stringify. This bug is about the private port slot which we may want to change from string to integer to deal better with the 2^16 limit.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>119519</commentid>
    <comment_count>4</comment_count>
    <who name="Sam Ruby">rubys</who>
    <bug_when>2015-04-15 07:20:43 +0000</bug_when>
    <thetext>Current test results show that the case being discussed on the IO.JS issue is one where four current browsers come up with four different results:

https://url.spec.whatwg.org/interop/test-results/c6c0953a53?select=current

Browser vendor review of the spec would be helpful.

See also: https://lists.w3.org/Archives/Public/public-url/2015Apr/0000.html</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>119520</commentid>
    <comment_count>5</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2015-04-15 07:25:42 +0000</bug_when>
    <thetext>Not sure why we need to discuss this on a (new?) mailing list. That test is not testing API. And this bug is not about the API.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>119534</commentid>
    <comment_count>6</comment_count>
    <who name="Domenic Denicola">d</who>
    <bug_when>2015-04-15 14:29:35 +0000</bug_when>
    <thetext>Thanks for taking the time to help Sam. (Although agreed that a new mailing list not a great idea here.)

As Anne points out, there&apos;s a difference between parsing (what that test tests) and the setter. For example in Chrome 999999 parses as &quot;0&quot;, whereas when using the setter it simply ignores any values above 65535.

Anne, would you prefer the question of the setter behavior in a separate bug, since you say this one is not about the API? Or should we assume the setter always has the same behavior as the parser, and continue using this bug for the former?</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>119535</commentid>
    <comment_count>7</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2015-04-15 14:46:04 +0000</bug_when>
    <thetext>I&apos;m okay with using this bug for how port should work in general.</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>119558</commentid>
    <comment_count>8</comment_count>
    <who name="Simon Pieters">zcorpan</who>
    <bug_when>2015-04-16 07:41:36 +0000</bug_when>
    <thetext>(In reply to Domenic Denicola from comment #6)
&gt; For example in Chrome 999999 parses as &quot;0&quot;,

Yes.

&gt; whereas
&gt; when using the setter it simply ignores any values above 65535.

No, it uses mod 2^16 AFAICT

http://software.hixie.ch/utilities/js/live-dom-viewer/saved/3500</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>121946</commentid>
    <comment_count>9</comment_count>
    <who name="Simon Sapin">simon.sapin</who>
    <bug_when>2015-07-10 15:13:48 +0000</bug_when>
    <thetext>Valentin Gosu from the Necko team is in favor of restricting port numbers to the range of unsigned 16 bit integers: https://github.com/servo/rust-url/issues/115#issuecomment-120059106

(This will probably happen as part of switching Gecko to rust-url: https://bugzilla.mozilla.org/show_bug.cgi?id=1151899 )</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>121982</commentid>
    <comment_count>10</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2015-07-12 07:21:21 +0000</bug_when>
    <thetext>He brings up an interesting point. That if we change the type we need to consider the default port case. So I guess it&apos;d have to be (null or 16-bit integer).</thetext>
  </long_desc><long_desc isprivate="0" >
    <commentid>122617</commentid>
    <comment_count>11</comment_count>
    <who name="Anne">annevk</who>
    <bug_when>2015-08-14 14:38:11 +0000</bug_when>
    <thetext>Thank you for the report. I decided against Chrome and made the parser and the setter behave identically for overflow values. I hope that is compatible.

https://github.com/whatwg/url/commit/c3a454c073d6bf9f24d8ee2b5c3e6e006b943777</thetext>
  </long_desc>
      
      

    </bug>

</bugzilla>