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

Make dummyURL from the basic URL parser with a special scheme #269

Merged
merged 4 commits into from
Mar 26, 2025
Merged
Changes from all commits
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
28 changes: 17 additions & 11 deletions spec.bs
Original file line number Diff line number Diff line change
Expand Up @@ -599,6 +599,13 @@ A <dfn>component</dfn> is a [=struct=] with the following [=struct/items=]:
1. Return |result|.
</div>

<div algorithm>
To <dfn export for="URL pattern">create a dummy URL</dfn>:

1. Let |dummyInput| be "`https://dummy.invalid/`".
1. Return the result of running the [=basic URL parser=] on |dummyInput|.
</div>

The <dfn>default options</dfn> is an [=options=] [=struct=] with [=options/delimiter code point=] set to the empty string and [=options/prefix code point=] set to the empty string.

The <dfn>hostname options</dfn> is an [=options=] [=struct=] with [=options/delimiter code point=] set "`.`" and [=options/prefix code point=] set to the empty string.
Expand Down Expand Up @@ -1704,18 +1711,17 @@ To <dfn>convert a modifier to a string</dfn> given a [=part/modifier=] |modifier
To <dfn>canonicalize a protocol</dfn> given a string |value|:

1. If |value| is the empty string, return |value|.
1. Let |dummyURL| be a new [=URL record=].
1. Let |parseResult| be the result of running the [=basic URL parser=] given |value| followed by "`://dummy.test`", with |dummyURL| as <i>[=basic URL parser/url=]</i>.
1. Let |parseResult| be the result of running the [=basic URL parser=] given |value| followed by "`://dummy.invalid/`".
<p class="note">Note, [=basic URL parser/state override=] is not used here because it enforces restrictions that are only appropriate for the {{URL/protocol}} setter. Instead we use the protocol to parse a dummy URL using the normal parsing entry point.</p>
1. If |parseResult| is failure, then throw a {{TypeError}}.
1. Return |dummyURL|'s [=url/scheme=].
1. Return |parseResult|'s [=url/scheme=].
</div>

<div algorithm>
To <dfn>canonicalize a username</dfn> given a string |value|:

1. If |value| is the empty string, return |value|.
1. Let |dummyURL| be a new [=URL record=].
1. Let |dummyURL| be the result of [=creating a dummy URL=].
1. [=Set the username=] given |dummyURL| and |value|.
1. Return |dummyURL|'s [=url/username=].
</div>
Expand All @@ -1724,7 +1730,7 @@ To <dfn>convert a modifier to a string</dfn> given a [=part/modifier=] |modifier
To <dfn>canonicalize a password</dfn> given a string |value|:

1. If |value| is the empty string, return |value|.
1. Let |dummyURL| be a new [=URL record=].
1. Let |dummyURL| be the result of [=creating a dummy URL=].
1. [=Set the password=] given |dummyURL| and |value|.
1. Return |dummyURL|'s [=url/password=].
</div>
Expand All @@ -1733,7 +1739,7 @@ To <dfn>convert a modifier to a string</dfn> given a [=part/modifier=] |modifier
To <dfn>canonicalize a hostname</dfn> given a string |value|:

1. If |value| is the empty string, return |value|.
1. Let |dummyURL| be a new [=URL record=].
1. Let |dummyURL| be the result of [=creating a dummy URL=].
1. Let |parseResult| be the result of running the [=basic URL parser=] given |value| with |dummyURL| as <i>[=basic URL parser/url=]</i> and [=hostname state=] as <i>[=basic URL parser/state override=]</i>.
1. If |parseResult| is failure, then throw a {{TypeError}}.
1. Return |dummyURL|'s [=url/host=], [=host serializer|serialized=], or empty string if it is null.
Expand All @@ -1760,7 +1766,7 @@ To <dfn>convert a modifier to a string</dfn> given a [=part/modifier=] |modifier
To <dfn>canonicalize a port</dfn> given a string |portValue| and optionally a string |protocolValue|:

1. If |portValue| is the empty string, return |portValue|.
1. Let |dummyURL| be a new [=URL record=].
1. Let |dummyURL| be the result of [=creating a dummy URL=].
1. If |protocolValue| was given, then set |dummyURL|'s [=url/scheme=] to |protocolValue|.
<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>.
Expand All @@ -1779,7 +1785,7 @@ To <dfn>convert a modifier to a string</dfn> given a [=part/modifier=] |modifier
<p>Note, implementations are free to simply disable slash prepending in their URL parsing code instead of paying the performance penalty of inserting and removing characters in this algorithm.
</div>
1. Append |value| to the end of |modified value|.
1. Let |dummyURL| be a new [=URL record=].
1. Let |dummyURL| be the result of [=creating a dummy URL=].
1. Run [=basic URL parser=] given |modified value| with |dummyURL| as <i>[=basic URL parser/url=]</i> and [=path start state=] as <i>[=basic URL parser/state override=]</i>.
1. Let |result| be the result of [=URL path serializing=] |dummyURL|.
1. If |leading slash| is false, then set |result| to the [=code point substring to the end of the string|code point substring=] from 2 to the end of the string within |result|.
Expand All @@ -1790,7 +1796,7 @@ To <dfn>convert a modifier to a string</dfn> given a [=part/modifier=] |modifier
To <dfn>canonicalize an opaque pathname</dfn> given a string |value|:

1. If |value| is the empty string, return |value|.
1. Let |dummyURL| be a new [=URL record=].
1. Let |dummyURL| be the result of [=creating a dummy URL=].
1. Set |dummyURL|'s [=url/path=] to the empty string.
1. Let |parseResult| be the result of running [=basic URL parser|URL parsing=] given |value| with |dummyURL| as <i>[=basic URL parser/url=]</i> and [=basic URL parser/opaque path state=] as <i>[=basic URL parser/state override=]</i>.
1. If |parseResult| is failure, then throw a {{TypeError}}.
Expand All @@ -1801,7 +1807,7 @@ To <dfn>convert a modifier to a string</dfn> given a [=part/modifier=] |modifier
To <dfn>canonicalize a search</dfn> given a string |value|:

1. If |value| is the empty string, return |value|.
1. Let |dummyURL| be a new [=URL record=].
1. Let |dummyURL| be the result of [=creating a dummy URL=].
1. Set |dummyURL|'s [=url/query=] to the empty string.
1. Run [=basic URL parser=] given |value| with |dummyURL| as <i>[=basic URL parser/url=]</i> and [=query state=] as <i>[=basic URL parser/state override=]</i>.
1. Return |dummyURL|'s [=url/query=].
Expand All @@ -1811,7 +1817,7 @@ To <dfn>convert a modifier to a string</dfn> given a [=part/modifier=] |modifier
To <dfn>canonicalize a hash</dfn> given a string |value|:

1. If |value| is the empty string, return |value|.
1. Let |dummyURL| be a new [=URL record=].
1. Let |dummyURL| be the result of [=creating a dummy URL=].
1. Set |dummyURL|'s [=url/fragment=] to the empty string.
1. Run [=basic URL parser=] given |value| with |dummyURL| as <i>[=basic URL parser/url=]</i> and [=fragment state=] as <i>[=basic URL parser/state override=]</i>.
1. Return |dummyURL|'s [=url/fragment=].
Expand Down