Bug 216115 - new URL("#") should throw an error
Summary: new URL("#") should throw an error
Status: RESOLVED FIXED
Alias: None
Product: WebKit
Classification: Unclassified
Component: Web Template Framework (show other bugs)
Version: WebKit Nightly Build
Hardware: Unspecified Unspecified
: P2 Normal
Assignee: Alex Christensen
URL:
Keywords: InRadar
: 216841 (view as bug list)
Depends on:
Blocks:
 
Reported: 2020-09-02 20:48 PDT by Yusuke Suzuki
Modified: 2022-07-04 22:34 PDT (History)
12 users (show)

See Also:


Attachments
Patch (5.15 KB, patch)
2020-09-08 12:09 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff
Patch (6.21 KB, patch)
2020-09-08 12:50 PDT, Alex Christensen
no flags Details | Formatted Diff | Diff

Note You need to log in before you can comment on or make changes to this bug.
Description Yusuke Suzuki 2020-09-02 20:48:15 PDT
https://github.com/whatwg/url/issues/539
Comment 1 Radar WebKit Bug Importer 2020-09-02 20:48:46 PDT
<rdar://problem/68252256>
Comment 2 Alex Christensen 2020-09-08 12:09:41 PDT
Created attachment 408251 [details]
Patch
Comment 3 Yusuke Suzuki 2020-09-08 12:15:11 PDT
Comment on attachment 408251 [details]
Patch

r=me
Comment 4 Darin Adler 2020-09-08 12:18:21 PDT
Comment on attachment 408251 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=408251&action=review

> Source/WebCore/html/DOMURL.h:-43
> -    static ExceptionOr<Ref<DOMURL>> create(const String& url, const DOMURL& base);

Glad we are getting rid of this. I guess the specification changed since we originally wrote the code.

> Source/WebCore/html/DOMURL.h:-44
> -    static ExceptionOr<Ref<DOMURL>> create(const String& url, const URL& base);

Does this "un-optimize" any call sites that were passing a URL before, or did those call sites just not exist?
Comment 5 Alex Christensen 2020-09-08 12:49:27 PDT
Comment on attachment 408251 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=408251&action=review

>> Source/WebCore/html/DOMURL.h:-44
>> -    static ExceptionOr<Ref<DOMURL>> create(const String& url, const URL& base);
> 
> Does this "un-optimize" any call sites that were passing a URL before, or did those call sites just not exist?

Yes, this un-optimizes passing a DOM URL as the second parameter.  It used to call the constructor with a const DOMURL& and after my first patch it turns it into a String and reparses it. I'll keep that optimization, which should be undetectable from JavaScript.
Comment 6 Alex Christensen 2020-09-08 12:50:27 PDT
Created attachment 408257 [details]
Patch
Comment 7 Darin Adler 2020-09-08 12:56:11 PDT
Comment on attachment 408257 [details]
Patch

I don’t understand how this fix works. If the baseURL is not valid, it seems like we’d get a TypeError exception, both before and after the patch. Where’s the fix?
Comment 8 Darin Adler 2020-09-08 12:57:18 PDT
Comment on attachment 408257 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=408257&action=review

> Source/WebCore/html/DOMURL.cpp:-51
> -    if (!base.isValid())
> -        return Exception { TypeError };

Wouldn’t a better fix be to add a special case to allow null here.

> Source/WebCore/html/DOMURL.cpp:-60
> -    return create(url, base.isNull() ? aboutBlankURL() : URL { URL { }, base });

And remove the special case for null here?
Comment 9 Alex Christensen 2020-09-08 13:04:08 PDT
Comment on attachment 408257 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=408257&action=review

>> Source/WebCore/html/DOMURL.cpp:-51
>> -        return Exception { TypeError };
> 
> Wouldn’t a better fix be to add a special case to allow null here.

This is called from DOMURL::create(const String&, const DOMURL&) where we know the base is non-null and valid.  That would be an unneeded check.  It would probably be close to equivalent and the difference would probably be undetectable from JS, but I like the logic like this better.

>> Source/WebCore/html/DOMURL.cpp:-60
>> -    return create(url, base.isNull() ? aboutBlankURL() : URL { URL { }, base });
> 
> And remove the special case for null here?

We need a check for null here because it is ok to not specify the base, in which case baseURL would be null which should not throw a type error.
Comment 10 Alex Christensen 2020-09-08 14:09:03 PDT
http://trac.webkit.org/r266748
Comment 11 Devin Rousso 2020-09-08 15:35:13 PDT
Comment on attachment 408257 [details]
Patch

View in context: https://bugs.webkit.org/attachment.cgi?id=408257&action=review

> LayoutTests/inspector/unit-tests/url-utilities.html:576
> +            test(new URL("#hash", "about:blank"), "about:blank");

This may cause issues in Web Inspector, specifically usage of `WI.urlWithoutFragment` and `parseURL`.  I don't know whether it's actually possible for Web Inspector to be given a Url that's just a fragment/hash, but I can't say for sure that it will never happen.
Comment 12 Alex Christensen 2020-09-08 16:30:06 PDT
Ok.  One can never be sure that a change won't cause any issues.  Let's keep our eyes out, and if we see any we can reconsider this.
Comment 13 Sam Sneddon [:gsnedders] 2022-07-04 22:34:18 PDT
*** Bug 216841 has been marked as a duplicate of this bug. ***