diff options
author | Idan Horowitz <idan.horowitz@gmail.com> | 2021-09-11 02:15:44 +0300 |
---|---|---|
committer | Idan Horowitz <idan.horowitz@gmail.com> | 2021-09-11 20:36:43 +0300 |
commit | 6704961c8250b44dc622e95821fd7e2b6bed673a (patch) | |
tree | bd540128659a2556acc51464552091fc3eb2e449 /Userland/Applications/Browser | |
parent | aba4c9579ff8d36f739eb221e330782e5c3a5d9d (diff) | |
download | serenity-6704961c8250b44dc622e95821fd7e2b6bed673a.zip |
AK: Replace the mutable String::replace API with an immutable version
This removes the awkward String::replace API which was the only String
API which mutated the String and replaces it with a new immutable
version that returns a new String with the replacements applied. This
also fixes a couple of UAFs that were caused by the use of this API.
As an optimization an equivalent StringView::replace API was also added
to remove an unnecessary String allocations in the format of:
`String { view }.replace(...);`
Diffstat (limited to 'Userland/Applications/Browser')
-rw-r--r-- | Userland/Applications/Browser/Tab.cpp | 7 |
1 files changed, 2 insertions, 5 deletions
diff --git a/Userland/Applications/Browser/Tab.cpp b/Userland/Applications/Browser/Tab.cpp index 0482b3a783..f043adb032 100644 --- a/Userland/Applications/Browser/Tab.cpp +++ b/Userland/Applications/Browser/Tab.cpp @@ -40,11 +40,8 @@ namespace Browser { URL url_from_user_input(const String& input) { - if (input.starts_with("?") && !g_search_engine.is_null()) { - auto url = g_search_engine; - url.replace("{}", URL::percent_encode(input.substring_view(1))); - return URL(url); - } + if (input.starts_with("?") && !g_search_engine.is_null()) + return URL(g_search_engine.replace("{}", URL::percent_encode(input.substring_view(1)))); auto url = URL(input); if (url.is_valid()) |