Bug 210431

Summary: Move URL to use StringView when returning substrings of the URL
Product: WebKit Reporter: Darin Adler <darin>
Component: Web Template FrameworkAssignee: Darin Adler <darin>
Status: RESOLVED FIXED    
Severity: Normal CC: aboxhall, andersca, apinheiro, benjamin, berto, calvaris, cdumez, cfleizach, cgarcia, cmarcelo, dmazzoni, eric.carlson, esprehn+autocc, ews-watchlist, galpeter, glenn, gustavo, gyuyoung.kim, japhet, jcraig, jdiggs, jer.noble, kangil.han, menard, mifenton, mmaxfield, philipj, pnormand, samuel_white, sergio, toyoshim, vjaquez, webkit-bug-importer, youennf, yutak
Priority: P2 Keywords: InRadar
Version: WebKit Nightly Build   
Hardware: Unspecified   
OS: Unspecified   
See Also: https://bugs.webkit.org/show_bug.cgi?id=211169
Attachments:
Description Flags
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch
none
Patch andersca: review+

Description Darin Adler 2020-04-13 09:07:09 PDT
Move URL to use StringView when returning substrings of the URL
Comment 1 Darin Adler 2020-04-13 19:24:36 PDT Comment hidden (obsolete)
Comment 2 Darin Adler 2020-04-13 20:29:21 PDT Comment hidden (obsolete)
Comment 3 Darin Adler 2020-04-13 20:40:52 PDT Comment hidden (obsolete)
Comment 4 Darin Adler 2020-04-14 09:49:05 PDT Comment hidden (obsolete)
Comment 5 Darin Adler 2020-04-17 10:27:02 PDT Comment hidden (obsolete)
Comment 6 Darin Adler 2020-04-20 12:42:48 PDT Comment hidden (obsolete)
Comment 7 Darin Adler 2020-04-21 21:29:19 PDT Comment hidden (obsolete)
Comment 8 Darin Adler 2020-04-22 18:11:05 PDT Comment hidden (obsolete)
Comment 9 Darin Adler 2020-04-22 22:00:46 PDT Comment hidden (obsolete)
Comment 10 Darin Adler 2020-04-23 18:40:06 PDT Comment hidden (obsolete)
Comment 11 Darin Adler 2020-04-24 09:30:52 PDT
Created attachment 397462 [details]
Patch
Comment 12 Darin Adler 2020-04-24 11:30:44 PDT
Created attachment 397474 [details]
Patch
Comment 13 Anders Carlsson 2020-04-25 08:02:15 PDT
Comment on attachment 397474 [details]
Patch

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

> Source/WTF/wtf/URL.cpp:169
> +    Vector<LChar, 512> percentDecoded;

512 seems kinda arbitrary and a little high.

> Source/WTF/wtf/text/StringView.cpp:315
> +// FIXME: Should this be named parseNumber<uint16_t> instead?

I like this idea.

> Source/WebCore/loader/appcache/ManifestParser.cpp:38
> +static StringView manifestPath(const URL& manifestURL)

Need to be careful about passing temporaries to this function!

> Source/WebCore/platform/network/curl/CurlProxySettings.cpp:40
> +constexpr uint16_t SocksProxyPort = 1080;

I'd keep this static.

> Source/WebCore/platform/win/PasteboardWin.cpp:-582
> -        String lastComponent = kurl.lastPathComponent();

kurl!

> Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp:1127
> +        || isPublicSuffix(m_currentRequest.url().host().toStringWithoutCopying());

Surprised isPublicSuffic doesn't take a StringView.

> Source/WebKitLegacy/win/Plugins/PluginDatabase.cpp:2
> + * Copyright (C) 2006, 2007 Apple Inc. All rights reserved.

Maybe change the copyright years here too.
Comment 14 Darin Adler 2020-04-25 11:01:53 PDT
Comment on attachment 397474 [details]
Patch

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

>> Source/WTF/wtf/URL.cpp:169
>> +    Vector<LChar, 512> percentDecoded;
> 
> 512 seems kinda arbitrary and a little high.

Was matching the other 512 numbers elsewhere in URL code, but those are for lengths of entire URLs. I would be happy to choose a different arbitrary number here. Maybe I should do a histogram of how this is actually used when doing some web browsing. For now, I’ll put 100 instead of 512 and I’ll even add a FIXME about setting the number better.

>> Source/WTF/wtf/text/StringView.cpp:315
>> +// FIXME: Should this be named parseNumber<uint16_t> instead?
> 
> I like this idea.

Just for the moment, I will leave it like this with this FIXME. But I will follow up.

>> Source/WebCore/loader/appcache/ManifestParser.cpp:38
>> +static StringView manifestPath(const URL& manifestURL)
> 
> Need to be careful about passing temporaries to this function!

Good point. Also true about all the URL functions; I did make them more dangerous with temporaries too.

Any thoughts on what I should do to lower the risk?

>> Source/WebCore/platform/network/curl/CurlProxySettings.cpp:40
>> +constexpr uint16_t SocksProxyPort = 1080;
> 
> I'd keep this static.

Alexey told me in the past that I should not write static in front of numeric constants in .cpp files. I will change this one back, but I am a bit confused about the tradeoffs. I looked it up and it seems that constexpr does not affect external vs. internal linkage, although it does make both "inline" and "const" redundant and unnecessary.

>> Source/WebCore/platform/win/PasteboardWin.cpp:-582
>> -        String lastComponent = kurl.lastPathComponent();
> 
> kurl!

I will leave this as a warning to future explorers, a concise way to say: "Abandon all hope, ye who enter here."

>> Source/WebKit/NetworkProcess/soup/NetworkDataTaskSoup.cpp:1127
>> +        || isPublicSuffix(m_currentRequest.url().host().toStringWithoutCopying());
> 
> Surprised isPublicSuffic doesn't take a StringView.

The Mac implementation easily could: it just creates a CF/NSString. It would take a little more work to wean the curl and soup implementations off of the convertToLowercaseWithoutLocale (incorrect in the curl one), convertToASCIILowercase (correct in the soup one), and utf8 functions. And this is soup-specific code.

I won’t do anything about this at this time.
Comment 15 Darin Adler 2020-04-25 11:02:02 PDT
Committed r260707: <https://trac.webkit.org/changeset/260707>
Comment 16 Radar WebKit Bug Importer 2020-04-25 11:02:23 PDT
<rdar://problem/62374069>
Comment 17 youenn fablet 2020-04-29 00:36:58 PDT
Comment on attachment 397474 [details]
Patch

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

> Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp:54
> +    url.setPort(origin.port());

We should probably reintroduce the nullopt check here.

> Source/WebCore/workers/service/server/SWServer.cpp:430
> +    url.setPort(*origin.port());

Ditto here.
Comment 18 youenn fablet 2020-04-29 00:38:48 PDT
(In reply to youenn fablet from comment #17)
> Comment on attachment 397474 [details]
> Patch
> 
> View in context:
> https://bugs.webkit.org/attachment.cgi?id=397474&action=review
> 
> > Source/WebCore/workers/service/context/ServiceWorkerThreadProxy.cpp:54
> > +    url.setPort(origin.port());
> 
> We should probably reintroduce the nullopt check here.
> 
> > Source/WebCore/workers/service/server/SWServer.cpp:430
> > +    url.setPort(*origin.port());
> 
> Ditto here.

Actually no, just remove * from SWServer.cpp:430