From 39428c3c74bd8ab7e00ce590178d7f0573a58b91 Mon Sep 17 00:00:00 2001 From: Ben Kelly Date: Fri, 3 Sep 2021 19:49:28 +0000 Subject: [PATCH] Make encoding callbacks short circuit on empty strings. (Fixes #118) --- spec.bs | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/spec.bs b/spec.bs index e976efd..b4c0a1d 100644 --- a/spec.bs +++ b/spec.bs @@ -1491,6 +1491,7 @@ 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=].

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.

@@ -1501,6 +1502,7 @@ To convert a modifier to a string given a [=part/modifier=] |modifier
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. [=Set the username=] given |dummyURL| and |value|. 1. Return |dummyURL|'s [=url/username=]. @@ -1509,6 +1511,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. [=Set the password=] given |dummyURL| and |value|. 1. Return |dummyURL|'s [=url/password=]. @@ -1517,6 +1520,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 |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}}. @@ -1526,6 +1530,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 |value| is the empty string, return |value|. 1. Let |dummyURL| be a new [=URL record=]. 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.

@@ -1537,6 +1542,7 @@ To convert a modifier to a string given a [=part/modifier=] |modifier
To canonicalize a pathname 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 [=basic URL parser=] given |value| with |dummyURL| as [=basic URL parser/url=] and [=path start state=] as [=basic URL parser/state override=]. 1. If |parseResult| is failure, then throw a {{TypeError}}. @@ -1546,6 +1552,7 @@ To convert a modifier to a string given a [=part/modifier=] |modifier
To canonicalize a cannot-be-a-base-URL pathname given a string |value|: + 1. If |value| is the empty string, return |value|. 1. Let |dummyURL| be a new [=URL record=]. 1. Set |dummyURL|'s [=url/path=][0] to 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 [=cannot be a base URL path state=] as [=basic URL parser/state override=]. @@ -1556,6 +1563,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. Set |dummyURL|'s [=url/query=] to the empty string. 1. Let |parseResult| be the result of running [=basic URL parser=] given |value| with |dummyURL| as [=basic URL parser/url=] and [=query state=] as [=basic URL parser/state override=]. @@ -1566,6 +1574,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. Set |dummyURL|'s [=url/fragment=] to the empty string. 1. Let |parseResult| be the result of running [=basic URL parser=] given |value| with |dummyURL| as [=basic URL parser/url=] and [=fragment state=] as [=basic URL parser/state override=].