mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 06:17:34 +00:00
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(...);`
This commit is contained in:
parent
aba4c9579f
commit
6704961c82
26 changed files with 72 additions and 118 deletions
|
@ -203,15 +203,12 @@ URL URLParser::parse(Badge<URL>, StringView const& raw_input, URL const* base_ur
|
|||
if (start_index >= end_index)
|
||||
return {};
|
||||
|
||||
auto processed_input = raw_input.substring_view(start_index, end_index - start_index);
|
||||
String processed_input = raw_input.substring_view(start_index, end_index - start_index);
|
||||
|
||||
// NOTE: This replaces all tab and newline characters with nothing.
|
||||
if (processed_input.contains("\t") || processed_input.contains("\n")) {
|
||||
report_validation_error();
|
||||
String processed_input_string(processed_input);
|
||||
processed_input_string.replace("\t", "", true);
|
||||
processed_input_string.replace("\n", "", true);
|
||||
processed_input = processed_input_string;
|
||||
processed_input = processed_input.replace("\t", "", true).replace("\n", "", true);
|
||||
}
|
||||
|
||||
State state = State::SchemeStart;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue