RESOLVED FIXED Bug 209173
Make URL::path() return a StringView
https://bugs.webkit.org/show_bug.cgi?id=209173
Summary Make URL::path() return a StringView
youenn fablet
Reported 2020-03-17 02:50:21 PDT
Make URL::path() return a StringView
Attachments
Patch (20.41 KB, patch)
2020-03-17 02:56 PDT, youenn fablet
no flags
Patch (20.96 KB, patch)
2020-03-17 03:12 PDT, youenn fablet
no flags
Patch (23.84 KB, patch)
2020-03-17 04:00 PDT, youenn fablet
no flags
Patch (26.56 KB, patch)
2020-03-17 04:28 PDT, youenn fablet
no flags
Patch (27.47 KB, patch)
2020-03-17 07:26 PDT, youenn fablet
no flags
Patch (28.90 KB, patch)
2020-03-18 07:18 PDT, youenn fablet
no flags
youenn fablet
Comment 1 2020-03-17 02:56:50 PDT
youenn fablet
Comment 2 2020-03-17 03:12:00 PDT
youenn fablet
Comment 3 2020-03-17 04:00:04 PDT
EWS Watchlist
Comment 4 2020-03-17 04:00:41 PDT
Thanks for the patch. If this patch contains new public API please make sure it follows the guidelines for new WebKit2 GTK+ API. See http://trac.webkit.org/wiki/WebKitGTK/AddingNewWebKit2API
youenn fablet
Comment 5 2020-03-17 04:28:47 PDT
youenn fablet
Comment 6 2020-03-17 07:26:03 PDT
Darin Adler
Comment 7 2020-03-17 12:57:26 PDT
Comment on attachment 393751 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=393751&action=review > Source/WebCore/Modules/plugins/YouTubePluginReplacement.cpp:262 > - } else if (startsWithLettersIgnoringASCIICase(path, "/v/") || startsWithLettersIgnoringASCIICase(path, "/e/")) { > + } else if (path.startsWithIgnoringASCIICase("/v/") || path.startsWithIgnoringASCIICase("/e/")) { We should add an overload of startsWithLettersIgnoringASCIICase for StringView rather than changing this code. > Source/WebCore/loader/FormSubmission.cpp:73 > - body = decodeURLEscapeSequences(body.replaceWithLiteral('&', "\r\n").replace('+', ' ') + "\r\n"); > + auto value = makeString(body.replaceWithLiteral('&', "\r\n").replace('+', ' '), "\r\n"); > + body = decodeURLEscapeSequences(value); I understand why we had to use makeString, but not why we have to break this into two lines. > Source/WebCore/page/Quirks.cpp:203 > - if (path.contains("notes") || url.fragmentIdentifier().contains("notes")) > + if (path.find("notes", 0) != notFound || url.fragmentIdentifier().contains("notes")) We should add a StringView::contains overload rather than changing this. > Source/WebCore/platform/text/TextEncoding.cpp:193 > if (string.isEmpty()) > - return string; > + return string.toString(); Seems a waste to call the general purpose toString function just to return either a null string or empty string. But I guess I don’t have a better idea. > Source/WebCore/platform/text/TextEncoding.h:31 > #include <wtf/URL.h> > +#include <wtf/text/StringView.h> > #include <wtf/text/WTFString.h> I am pretty sure some of these headers include others. We definitely don’t need to include all three.
youenn fablet
Comment 8 2020-03-18 07:18:37 PDT
youenn fablet
Comment 9 2020-03-18 08:44:13 PDT
(In reply to Darin Adler from comment #7) > Comment on attachment 393751 [details] > Patch > > View in context: > https://bugs.webkit.org/attachment.cgi?id=393751&action=review > > > Source/WebCore/Modules/plugins/YouTubePluginReplacement.cpp:262 > > - } else if (startsWithLettersIgnoringASCIICase(path, "/v/") || startsWithLettersIgnoringASCIICase(path, "/e/")) { > > + } else if (path.startsWithIgnoringASCIICase("/v/") || path.startsWithIgnoringASCIICase("/e/")) { > > We should add an overload of startsWithLettersIgnoringASCIICase for > StringView rather than changing this code. Done. > > > Source/WebCore/loader/FormSubmission.cpp:73 > > - body = decodeURLEscapeSequences(body.replaceWithLiteral('&', "\r\n").replace('+', ' ') + "\r\n"); > > + auto value = makeString(body.replaceWithLiteral('&', "\r\n").replace('+', ' '), "\r\n"); > > + body = decodeURLEscapeSequences(value); > > I understand why we had to use makeString, but not why we have to break this > into two lines. Reverted. > > Source/WebCore/page/Quirks.cpp:203 > > - if (path.contains("notes") || url.fragmentIdentifier().contains("notes")) > > + if (path.find("notes", 0) != notFound || url.fragmentIdentifier().contains("notes")) > > We should add a StringView::contains overload rather than changing this. Added. > > Source/WebCore/platform/text/TextEncoding.cpp:193 > > if (string.isEmpty()) > > - return string; > > + return string.toString(); > > Seems a waste to call the general purpose toString function just to return > either a null string or empty string. But I guess I don’t have a better idea. > > > Source/WebCore/platform/text/TextEncoding.h:31 > > #include <wtf/URL.h> > > +#include <wtf/text/StringView.h> > > #include <wtf/text/WTFString.h> > > I am pretty sure some of these headers include others. We definitely don’t > need to include all three. Removed WTFString.h
Alex Christensen
Comment 10 2020-03-18 09:31:56 PDT
Comment on attachment 393850 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=393850&action=review > Source/WebCore/platform/text/TextEncoding.cpp:193 > + return string.toString(); Does an empty StringView's .toString return "" or { }? I think we should return that here instead. > Source/WebCore/workers/service/ServiceWorkerJob.cpp:135 > + if (maxScopeString.isNull() || !scopeString.startsWith(maxScopeString)) Why did we add a null check here?
Darin Adler
Comment 11 2020-03-18 11:04:44 PDT
Comment on attachment 393850 [details] Patch View in context: https://bugs.webkit.org/attachment.cgi?id=393850&action=review >> Source/WebCore/platform/text/TextEncoding.cpp:193 >> + return string.toString(); > > Does an empty StringView's .toString return "" or { }? I think we should return that here instead. A StringView that returns true for isEmpty can be either empty or null; like String, AtomString, and const char*, StringView has distinct empty and null states. The toString function returns an empty or null String for those two different states. That pass through is accomplished by calling toString here. In this particular function it’s possible no one depends on this behavior, but this change does preserve it. >> Source/WebCore/workers/service/ServiceWorkerJob.cpp:135 >> + if (maxScopeString.isNull() || !scopeString.startsWith(maxScopeString)) > > Why did we add a null check here? That’s a good question. StringView and String startsWith functions should handle null strings in the same way and the change should not be necessary.
youenn fablet
Comment 12 2020-03-19 00:46:42 PDT
> >> Source/WebCore/workers/service/ServiceWorkerJob.cpp:135 > >> + if (maxScopeString.isNull() || !scopeString.startsWith(maxScopeString)) > > > > Why did we add a null check here? > > That’s a good question. StringView and String startsWith functions should > handle null strings in the same way and the change should not be necessary. String::startsWith(null) returns false. StringView::startsWith(null) returns true. Also, this additional check is nicely matching the wording of step 17 of https://w3c.github.io/ServiceWorker/#update. This subtlety is not great to me but I do not want to change it here. I would go with StringView behaviour.
youenn fablet
Comment 13 2020-03-19 00:53:22 PDT
EWS
Comment 14 2020-03-19 01:29:29 PDT
Committed r258685: <https://trac.webkit.org/changeset/258685> All reviewed patches have been landed. Closing bug and clearing flags on attachment 393850 [details].
Radar WebKit Bug Importer
Comment 15 2020-03-19 01:30:15 PDT
Note You need to log in before you can comment on or make changes to this bug.