fix: wide string concatenation (#40892)

* fix: wide string concatenation

* Use wstring_views to keep length in context

* forgot a space, oopsies
This commit is contained in:
Calvin 2024-01-07 22:02:20 -08:00 committed by GitHub
parent 3a22fd3216
commit 37630a6128
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 13 additions and 13 deletions

View file

@ -19,8 +19,8 @@
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/path_service.h"
#include "base/strings/strcat_win.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/strings/utf_string_conversions.h"
#include "base/win/registry.h"
#include "base/win/win_util.h"
@ -68,13 +68,13 @@ bool GetProtocolLaunchPath(gin::Arguments* args, std::wstring* exe) {
// Read in optional args arg
std::vector<std::wstring> launch_args;
if (args->GetNext(&launch_args) && !launch_args.empty())
*exe = base::UTF8ToWide(
base::StringPrintf("\"%ls\" \"%ls\" \"%%1\"", exe->c_str(),
base::JoinString(launch_args, L"\" \"").c_str()));
else
*exe =
base::UTF8ToWide(base::StringPrintf("\"%ls\" \"%%1\"", exe->c_str()));
if (args->GetNext(&launch_args) && !launch_args.empty()) {
std::wstring joined_args = base::JoinString(launch_args, L"\" \"");
*exe = base::StrCat({L"\"", *exe, L"\" \"", joined_args, L"\" \"%1\""});
} else {
*exe = base::StrCat({L"\"", *exe, L"\" \"%1\""});
}
return true;
}
@ -142,8 +142,7 @@ bool FormatCommandLineString(std::wstring* exe,
if (!launch_args.empty()) {
std::u16string joined_launch_args = base::JoinString(launch_args, u" ");
*exe = base::UTF8ToWide(base::StringPrintf(
"%ls %ls", exe->c_str(), base::as_wcstr(joined_launch_args)));
*exe = base::StrCat({*exe, L" ", base::AsWStringView(joined_launch_args)});
}
return true;

View file

@ -8,7 +8,8 @@
#include "base/logging.h"
#include "base/process/launch.h"
#include "base/strings/stringprintf.h"
#include "base/strings/strcat_win.h"
#include "base/strings/string_number_conversions_win.h"
#include "base/strings/utf_string_conversions.h"
#include "base/win/scoped_handle.h"
#include "sandbox/win/src/nt_internals.h"
@ -109,8 +110,8 @@ StringType AddQuoteForArg(const StringType& arg) {
} // namespace
StringType GetWaitEventName(base::ProcessId pid) {
return base::UTF8ToWide(
base::StringPrintf("%ls-%d", kWaitEventName, static_cast<int>(pid)));
return base::StrCat(
{kWaitEventName, L"-", base::NumberToWString(static_cast<int>(pid))});
}
StringType ArgvToCommandLineString(const StringVector& argv) {