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

Add URL.canParse() #763

Merged
merged 2 commits into from
Mar 20, 2023
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
47 changes: 36 additions & 11 deletions url.bs
Original file line number Diff line number Diff line change
Expand Up @@ -180,7 +180,7 @@ valid input. User agents, especially conformance checkers, are encouraged to rep
<td><dfn>IPv6-unclosed</dfn>
<td>
<p>An <a for=/>IPv6 address</a> is missing the closing U+005D (]).
<p class=example id=example-ipv6-unclosed"<code>https://[::1</code>"
<p class=example id=example-ipv6-unclosed>"<code>https://[::1</code>"
<td class=yes>Yes
<!-- IPv6 parser -->
<tr>
Expand Down Expand Up @@ -3321,6 +3321,8 @@ are encouraged to use an API suitable to their needs, which might not be this on
interface URL {
constructor(USVString url, optional USVString base);

static boolean canParse(USVString url, optional USVString base);

stringifier attribute USVString href;
readonly attribute USVString origin;
attribute USVString protocol;
Expand Down Expand Up @@ -3361,27 +3363,35 @@ interface URL {
<a for=URL>URL</a>'s <a for=url>path</a>.
</ol>

<hr>

<p id=constructors>The
<dfn constructor for=URL lt="URL(url, base)"><code>new URL(<var>url</var>, <var>base</var>)</code></dfn>
constructor steps are:
<p>The <dfn>API URL parser</dfn> takes a <a>scalar value string</a> <var>url</var> and an optional
null-or-<a>scalar value string</a> <var>base</var> (default null), and then runs these steps:

<ol>
<li><p>Let <var>parsedBase</var> be null.

<li>
<p>If <var>base</var> is given, then:
<p>If <var>base</var> is non-null:

<ol>
<li><p>Let <var>parsedBase</var> be the result of running the <a>basic URL parser</a> on
<li><p>Set <var>parsedBase</var> to the result of running the <a>basic URL parser</a> on
<var>base</var>.

<li><p>If <var>parsedBase</var> is failure, then <a>throw</a> a {{TypeError}}.
<li><p>If <var>parsedBase</var> is failure, then return failure.
</ol>

<li><p>Let <var>parsedURL</var> be the result of running the <a>basic URL parser</a> on
<var>url</var> with <var>parsedBase</var>.
<li><p>Return the result of running the <a>basic URL parser</a> on <var>url</var> with
<var>parsedBase</var>.
</ol>

<hr>

<p id=constructors>The
<dfn constructor for=URL lt="URL(url, base)"><code>new URL(<var>url</var>, <var>base</var>)</code></dfn>
constructor steps are:

<ol>
<li><p>Let <var>parsedURL</var> be the result of running the <a>API URL parser</a> on
<var>url</var> with <var>base</var>, if given.

<li><p>If <var>parsedURL</var> is failure, then <a>throw</a> a {{TypeError}}.

Expand Down Expand Up @@ -3432,6 +3442,20 @@ var url = new URL("🏳️‍🌈", new URL("https://pride.example/hello-world")
url.pathname // "/%F0%9F%8F%B3%EF%B8%8F%E2%80%8D%F0%9F%8C%88"</code></pre>
</div>

<hr>

<p>The static <dfn method for=URL><code>canParse(<var>url</var>, <var>base</var>)</code></dfn>
method steps are:

<ol>
<li><p>Let <var>parsedURL</var> be the result of running the <a>API URL parser</a> on
<var>url</var> with <var>base</var>, if given.

<li><p>If <var>parsedURL</var> is failure, then return false.

<li><p>Return true.
</ol>

<hr id=urlutils-members>

<p>The <dfn attribute for=URL><code>href</code></dfn> getter steps and the
Expand Down Expand Up @@ -3950,6 +3974,7 @@ Gavin Carothers,
Geoff Richards,
Glenn Maynard,
Gordon P. Hemsley,
hemanth,<!-- GitHub -->
Henri Sivonen,
Ian Hickson,
Ilya Grigorik,
Expand Down