diff --git a/spec.bs b/spec.bs index 9d97980..a500313 100644 --- a/spec.bs +++ b/spec.bs @@ -599,6 +599,13 @@ A component is a [=struct=] with the following [=struct/items=]: 1. Return |result|. +
+ To create a dummy URL: + + 1. Let |dummyInput| be "`https://dummy.invalid/`". + 1. Return the result of running the [=basic URL parser=] on |dummyInput|. +
+ The default options 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 hostname options is an [=options=] [=struct=] with [=options/delimiter code point=] set "`.`" and [=options/prefix code point=] set to the empty string. @@ -1704,18 +1711,17 @@ To convert a modifier to a string given a [=part/modifier=] |modifier To canonicalize a protocol 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 [=basic URL parser/url=]. + 1. Let |parseResult| be the result of running the [=basic URL parser=] given |value| followed by "`://dummy.invalid/`".

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.

1. If |parseResult| is failure, then throw a {{TypeError}}. - 1. Return |dummyURL|'s [=url/scheme=]. + 1. Return |parseResult|'s [=url/scheme=].
To canonicalize a username 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=].
@@ -1724,7 +1730,7 @@ To convert a modifier to a string given a [=part/modifier=] |modifier To canonicalize a password 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=]. @@ -1733,7 +1739,7 @@ To convert a modifier to a string given a [=part/modifier=] |modifier To canonicalize a hostname 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 [=basic URL parser/url=] and [=hostname state=] as [=basic URL parser/state override=]. 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. @@ -1760,7 +1766,7 @@ To convert a modifier to a string given a [=part/modifier=] |modifier To canonicalize a port 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|.

Note, we set the [=URL record=]'s [=url/scheme=] in order for the [=basic URL parser=] to recognize and normalize default port values.

1. Let |parseResult| be the result of running [=basic URL parser=] given |portValue| with |dummyURL| as [=basic URL parser/url=] and [=port state=] as [=basic URL parser/state override=]. @@ -1779,7 +1785,7 @@ To convert a modifier to a string given a [=part/modifier=] |modifier

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. 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 [=basic URL parser/url=] and [=path start state=] as [=basic URL parser/state override=]. 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|. @@ -1790,7 +1796,7 @@ To convert a modifier to a string given a [=part/modifier=] |modifier To canonicalize an opaque pathname 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 [=basic URL parser/url=] and [=basic URL parser/opaque path state=] as [=basic URL parser/state override=]. 1. If |parseResult| is failure, then throw a {{TypeError}}. @@ -1801,7 +1807,7 @@ To convert a modifier to a string given a [=part/modifier=] |modifier To canonicalize a search 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 [=basic URL parser/url=] and [=query state=] as [=basic URL parser/state override=]. 1. Return |dummyURL|'s [=url/query=]. @@ -1811,7 +1817,7 @@ To convert a modifier to a string given a [=part/modifier=] |modifier To canonicalize a hash 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 [=basic URL parser/url=] and [=fragment state=] as [=basic URL parser/state override=]. 1. Return |dummyURL|'s [=url/fragment=].