mirror of
https://github.com/RGBCube/serenity
synced 2025-07-26 00:37:35 +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
|
@ -114,15 +114,11 @@ int main(int argc, char* argv[])
|
|||
auto file = Core::File::construct();
|
||||
file->set_filename(make_path(section));
|
||||
|
||||
String pager_command = pager;
|
||||
if (!pager) {
|
||||
String clean_name(name);
|
||||
String clean_section(section);
|
||||
|
||||
clean_name.replace("'", "'\\''");
|
||||
clean_section.replace("'", "'\\''");
|
||||
pager_command = String::formatted("less -P 'Manual Page {}({}) line %l?e (END):.'", clean_name, clean_section);
|
||||
}
|
||||
String pager_command;
|
||||
if (pager)
|
||||
pager_command = pager;
|
||||
else
|
||||
pager_command = String::formatted("less -P 'Manual Page {}({}) line %l?e (END):.'", StringView(name).replace("'", "'\\''"), StringView(section).replace("'", "'\\''"));
|
||||
pid_t pager_pid = pipe_to_pager(pager_command);
|
||||
|
||||
if (!file->open(Core::OpenMode::ReadOnly)) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue