Skip to content

Commit

Permalink
Correct processing of non-string members of a base URL record
Browse files Browse the repository at this point in the history
Some of these values may be null (or in the case of port, an integer) and
must be converted to strings before they can be applied to URLPatternInit.

The conversion of the port to an integer is also necessary in the encoding
callbacks.

Addresses #202, at least in part.
  • Loading branch information
jeremyroman authored Jan 16, 2024
1 parent 531a2cc commit 3edcad4
Showing 1 changed file with 19 additions and 5 deletions.
24 changes: 19 additions & 5 deletions spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ spec: ECMASCRIPT; urlPrefix: https://tc39.es/ecma262/
type: dfn
text: IdentifierPart; url: #prod-IdentifierPart
text: IdentifierStart; url: #prod-IdentifierStart
spec: URL; urlPrefix: https://url.spec.whatwg.org/
type: dfn
text: serialize an integer; url: #serialize-an-integer
</pre>

<h2 id=urlpattern-class>The {{URLPattern}} class</h2>
Expand Down Expand Up @@ -1737,7 +1740,7 @@ To <dfn>convert a modifier to a string</dfn> given a [=part/modifier=] |modifier
<p class="note">Note, we set the [=URL record=]'s [=url/scheme=] in order for the [=basic URL parser=] to recognize and normalize default port values.</p>
1. Let |parseResult| be the result of running [=basic URL parser=] given |portValue| with |dummyURL| as <i>[=basic URL parser/url=]</i> and [=port state=] as <i>[=basic URL parser/state override=]</i>.
1. If |parseResult| is failure, then throw a {{TypeError}}.
1. Return |dummyURL|'s [=url/port=] or empty string if it is null.
1. Return |dummyURL|'s [=url/port=], [=serialize an integer|serialized=], or empty string if it is null.
</div>

<div algorithm>
Expand Down Expand Up @@ -1823,11 +1826,22 @@ To <dfn>convert a modifier to a string</dfn> given a [=part/modifier=] |modifier
1. If |init|["{{URLPatternInit/protocol}}"] does not [=map/exist=], then set |result|["{{URLPatternInit/protocol}}"] to the result of [=processing a base URL string=] given |baseURL|'s [=url/scheme=] and |type|.
1. If |type| is not "`pattern`" and |init| [=map/contains=] none of "{{URLPatternInit/protocol}}", "{{URLPatternInit/hostname}}", "{{URLPatternInit/port}}" and "{{URLPatternInit/username}}", then set |result|["{{URLPatternInit/username}}"] to the result of [=processing a base URL string=] given |baseURL|'s [=url/username=] and |type|.
1. If |type| is not "`pattern`" and |init| [=map/contains=] none of "{{URLPatternInit/protocol}}", "{{URLPatternInit/hostname}}", "{{URLPatternInit/port}}", "{{URLPatternInit/username}}" and "{{URLPatternInit/password}}", then set |result|["{{URLPatternInit/password}}"] to the result of [=processing a base URL string=] given |baseURL|'s [=url/password=] and |type|.
1. If |init| [=map/contains=] neither "{{URLPatternInit/protocol}}" nor "{{URLPatternInit/hostname}}", then set |result|["{{URLPatternInit/hostname}}"] to the result of [=processing a base URL string=] given |baseURL|'s [=url/host=] and |type|.
1. If |init| [=map/contains=] none of "{{URLPatternInit/protocol}}", "{{URLPatternInit/hostname}}", and "{{URLPatternInit/port}}", then set |result|["{{URLPatternInit/port}}"] to the result of [=processing a base URL string=] given |baseURL|'s [=url/port=] and |type|.
1. If |init| [=map/contains=] neither "{{URLPatternInit/protocol}}" nor "{{URLPatternInit/hostname}}", then:
1. Let |baseHost| be |baseURL|'s [=url/host=].
1. If |baseHost| is null, then set |baseHost| to the empty string.
1. Set |result|["{{URLPatternInit/hostname}}"] to the result of [=processing a base URL string=] given |baseHost| and |type|.
1. If |init| [=map/contains=] none of "{{URLPatternInit/protocol}}", "{{URLPatternInit/hostname}}", and "{{URLPatternInit/port}}", then:
1. If |baseURL|'s [=url/port=] is null, then set |result|["{{URLPatternInit/port}}"] to the empty string.
1. Otherwise, set |result|["{{URLPatternInit/port}}"] to |baseURL|'s [=url/port=], [=serialize an integer|serialized=].
1. If |init| [=map/contains=] none of "{{URLPatternInit/protocol}}", "{{URLPatternInit/hostname}}", "{{URLPatternInit/port}}", and "{{URLPatternInit/pathname}}", then set |result|["{{URLPatternInit/pathname}}"] to the result of [=processing a base URL string=] given the result of [=URL path serializing=] |baseURL| and |type|.
1. If |init| [=map/contains=] none of "{{URLPatternInit/protocol}}", "{{URLPatternInit/hostname}}", "{{URLPatternInit/port}}", "{{URLPatternInit/pathname}}", and "{{URLPatternInit/search}}", then set |result|["{{URLPatternInit/search}}"] to the result of [=processing a base URL string=] given |baseURL|'s [=url/query=] and |type|.
1. If |init| [=map/contains=] none of "{{URLPatternInit/protocol}}", "{{URLPatternInit/hostname}}", "{{URLPatternInit/port}}", "{{URLPatternInit/pathname}}", "{{URLPatternInit/search}}", and "{{URLPatternInit/hash}}", then set |result|["{{URLPatternInit/hash}}"] to the result of [=processing a base URL string=] given |baseURL|'s [=url/fragment=] and |type|.
1. If |init| [=map/contains=] none of "{{URLPatternInit/protocol}}", "{{URLPatternInit/hostname}}", "{{URLPatternInit/port}}", "{{URLPatternInit/pathname}}", and "{{URLPatternInit/search}}", then:
1. Let |baseQuery| be |baseURL|'s [=url/query=].
1. If |baseQuery| is null, then set |baseQuery| to the empty string.
1. Set |result|["{{URLPatternInit/search}}"] to the result of [=processing a base URL string=] given |baseQuery| and |type|.
1. If |init| [=map/contains=] none of "{{URLPatternInit/protocol}}", "{{URLPatternInit/hostname}}", "{{URLPatternInit/port}}", "{{URLPatternInit/pathname}}", "{{URLPatternInit/search}}", and "{{URLPatternInit/hash}}", then:
1. Let |baseFragment| be |baseURL|'s [=url/fragment=].
1. If |baseFragment| is null, then set |baseFragment| to the empty string.
1. Set |result|["{{URLPatternInit/hash}}"] to the result of [=processing a base URL string=] given |baseFragment| and |type|.
1. If |init|["{{URLPatternInit/protocol}}"] [=map/exists=], then set |result|["{{URLPatternInit/protocol}}"] to the result of [=process protocol for init=] given |init|["{{URLPatternInit/protocol}}"] and |type|.
1. If |init|["{{URLPatternInit/username}}"] [=map/exists=], then set |result|["{{URLPatternInit/username}}"] to the result of [=process username for init=] given |init|["{{URLPatternInit/username}}"] and |type|.
1. If |init|["{{URLPatternInit/password}}"] [=map/exists=], then set |result|["{{URLPatternInit/password}}"] to the result of [=process password for init=] given |init|["{{URLPatternInit/password}}"] and |type|.
Expand Down

0 comments on commit 3edcad4

Please sign in to comment.