Skip to content

Commit ae3c28b

Browse files
authored
Add URL.canParse()
Tests: web-platform-tests/wpt#39069. Fixes #713.
1 parent 6d4734a commit ae3c28b

File tree

1 file changed

+36
-11
lines changed

1 file changed

+36
-11
lines changed

url.bs

Lines changed: 36 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -180,7 +180,7 @@ valid input. User agents, especially conformance checkers, are encouraged to rep
180180
<td><dfn>IPv6-unclosed</dfn>
181181
<td>
182182
<p>An <a for=/>IPv6 address</a> is missing the closing U+005D (]).
183-
<p class=example id=example-ipv6-unclosed"<code>https://[::1</code>"
183+
<p class=example id=example-ipv6-unclosed>"<code>https://[::1</code>"
184184
<td class=yes>Yes
185185
<!-- IPv6 parser -->
186186
<tr>
@@ -3321,6 +3321,8 @@ are encouraged to use an API suitable to their needs, which might not be this on
33213321
interface URL {
33223322
constructor(USVString url, optional USVString base);
33233323

3324+
static boolean canParse(USVString url, optional USVString base);
3325+
33243326
stringifier attribute USVString href;
33253327
readonly attribute USVString origin;
33263328
attribute USVString protocol;
@@ -3361,27 +3363,35 @@ interface URL {
33613363
<a for=URL>URL</a>'s <a for=url>path</a>.
33623364
</ol>
33633365

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

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

33733372
<li>
3374-
<p>If <var>base</var> is given, then:
3373+
<p>If <var>base</var> is non-null:
33753374

33763375
<ol>
3377-
<li><p>Let <var>parsedBase</var> be the result of running the <a>basic URL parser</a> on
3376+
<li><p>Set <var>parsedBase</var> to the result of running the <a>basic URL parser</a> on
33783377
<var>base</var>.
33793378

3380-
<li><p>If <var>parsedBase</var> is failure, then <a>throw</a> a {{TypeError}}.
3379+
<li><p>If <var>parsedBase</var> is failure, then return failure.
33813380
</ol>
33823381

3383-
<li><p>Let <var>parsedURL</var> be the result of running the <a>basic URL parser</a> on
3384-
<var>url</var> with <var>parsedBase</var>.
3382+
<li><p>Return the result of running the <a>basic URL parser</a> on <var>url</var> with
3383+
<var>parsedBase</var>.
3384+
</ol>
3385+
3386+
<hr>
3387+
3388+
<p id=constructors>The
3389+
<dfn constructor for=URL lt="URL(url, base)"><code>new URL(<var>url</var>, <var>base</var>)</code></dfn>
3390+
constructor steps are:
3391+
3392+
<ol>
3393+
<li><p>Let <var>parsedURL</var> be the result of running the <a>API URL parser</a> on
3394+
<var>url</var> with <var>base</var>, if given.
33853395

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

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

3445+
<hr>
3446+
3447+
<p>The static <dfn method for=URL><code>canParse(<var>url</var>, <var>base</var>)</code></dfn>
3448+
method steps are:
3449+
3450+
<ol>
3451+
<li><p>Let <var>parsedURL</var> be the result of running the <a>API URL parser</a> on
3452+
<var>url</var> with <var>base</var>, if given.
3453+
3454+
<li><p>If <var>parsedURL</var> is failure, then return false.
3455+
3456+
<li><p>Return true.
3457+
</ol>
3458+
34353459
<hr id=urlutils-members>
34363460

34373461
<p>The <dfn attribute for=URL><code>href</code></dfn> getter steps and the
@@ -3950,6 +3974,7 @@ Gavin Carothers,
39503974
Geoff Richards,
39513975
Glenn Maynard,
39523976
Gordon P. Hemsley,
3977+
hemanth,<!-- GitHub -->
39533978
Henri Sivonen,
39543979
Ian Hickson,
39553980
Ilya Grigorik,

0 commit comments

Comments
 (0)