mirror of
https://github.com/RGBCube/serenity
synced 2025-07-28 04:27:45 +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
|
@ -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())
|
||||
|
|
|
@ -76,8 +76,7 @@ Result<ByteBuffer, String> FindDialog::process_input(String text_value, OptionId
|
|||
}
|
||||
|
||||
case OPTION_HEX_VALUE: {
|
||||
text_value.replace(" ", "", true);
|
||||
auto decoded = decode_hex(text_value.substring_view(0, text_value.length()));
|
||||
auto decoded = decode_hex(text_value.replace(" ", "", true));
|
||||
if (!decoded.has_value())
|
||||
return String("Input contains invalid hex values.");
|
||||
|
||||
|
|
|
@ -130,9 +130,8 @@ GoToOffsetDialog::GoToOffsetDialog()
|
|||
m_text_editor->on_change = [this]() {
|
||||
auto text = m_text_editor->text();
|
||||
if (text.starts_with("0x")) {
|
||||
text.replace("0x", "");
|
||||
m_offset_type_box->set_selected_index(1);
|
||||
m_text_editor->set_text(text);
|
||||
m_text_editor->set_text(text.replace("0x", ""));
|
||||
}
|
||||
update_statusbar();
|
||||
};
|
||||
|
|
|
@ -83,8 +83,7 @@ int main(int argc, char** argv)
|
|||
|
||||
while (iterator.has_next()) {
|
||||
auto name = iterator.next_path();
|
||||
name.replace(".json", "");
|
||||
character_map_files.append(name);
|
||||
character_map_files.append(name.replace(".json", ""));
|
||||
}
|
||||
quick_sort(character_map_files);
|
||||
|
||||
|
|
|
@ -162,8 +162,7 @@ static RefPtr<GUI::Window> create_settings_window(VT::TerminalWidget& terminal)
|
|||
Core::DirIterator iterator("/res/terminal-colors", Core::DirIterator::SkipParentAndBaseDir);
|
||||
while (iterator.has_next()) {
|
||||
auto path = iterator.next_path();
|
||||
path.replace(".ini", "");
|
||||
color_scheme_names.append(path);
|
||||
color_scheme_names.append(path.replace(".ini", ""));
|
||||
}
|
||||
quick_sort(color_scheme_names);
|
||||
auto& color_scheme_combo = *settings.find_descendant_of_type_named<GUI::ComboBox>("color_scheme_combo");
|
||||
|
@ -199,11 +198,8 @@ static RefPtr<GUI::Window> create_find_window(VT::TerminalWidget& terminal)
|
|||
auto& find_textbox = find.add<GUI::TextBox>();
|
||||
find_textbox.set_fixed_width(230);
|
||||
find_textbox.set_focus(true);
|
||||
if (terminal.has_selection()) {
|
||||
String selected_text = terminal.selected_text();
|
||||
selected_text.replace("\n", " ", true);
|
||||
find_textbox.set_text(selected_text);
|
||||
}
|
||||
if (terminal.has_selection())
|
||||
find_textbox.set_text(terminal.selected_text().replace("\n", " ", true));
|
||||
auto& find_backwards = find.add<GUI::Button>();
|
||||
find_backwards.set_fixed_width(25);
|
||||
find_backwards.set_icon(Gfx::Bitmap::try_load_from_file("/res/icons/16x16/upward-triangle.png"));
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue