Skip to content

Commit

Permalink
Add URL.canParse()
Browse files Browse the repository at this point in the history
  • Loading branch information
annevk authored Mar 20, 2023
1 parent 6d4734a commit ae3c28b
Showing 1 changed file with 36 additions and 11 deletions.
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 -->

This comment has been minimized.

Copy link
@hemanth

hemanth Apr 30, 2023

@annevk can we change it to Hemanth HM ?

Edit: I can do a PR if so.

Henri Sivonen,
Ian Hickson,
Ilya Grigorik,
Expand Down

0 comments on commit ae3c28b

Please sign in to comment.