Fix CefCommandLine character case requirements (fixes issue #1872)
Switch names will now be converted to lowercase ASCII on all platforms. Switch values will retain the original case and UTF8 encoding.
This commit is contained in:
parent
6516b569a9
commit
4d1c5ebdd2
|
@ -33,7 +33,7 @@
|
|||
// by hand. See the translator.README.txt file in the tools directory for
|
||||
// more information.
|
||||
//
|
||||
// $hash=5af5bf1e877dd53f21f751d332a9e2166817324c$
|
||||
// $hash=3ecebd6b30bb8fb837e062eacd021c1a1ff3620a$
|
||||
//
|
||||
|
||||
#ifndef CEF_INCLUDE_CAPI_CEF_COMMAND_LINE_CAPI_H_
|
||||
|
@ -53,8 +53,9 @@ extern "C" {
|
|||
// optionally have a value specified using the '=' delimiter (e.g.
|
||||
// "-switch=value"). An argument of "--" will terminate switch parsing with all
|
||||
// subsequent tokens, regardless of prefix, being interpreted as non-switch
|
||||
// arguments. Switch names are considered case-insensitive. This structure can
|
||||
// be used before cef_initialize() is called.
|
||||
// arguments. Switch names should be lowercase ASCII and will be converted to
|
||||
// such if necessary. Switch values will retain the original case and UTF8
|
||||
// encoding. This structure can be used before cef_initialize() is called.
|
||||
///
|
||||
typedef struct _cef_command_line_t {
|
||||
///
|
||||
|
|
|
@ -49,8 +49,9 @@
|
|||
// optionally have a value specified using the '=' delimiter (e.g.
|
||||
// "-switch=value"). An argument of "--" will terminate switch parsing with all
|
||||
// subsequent tokens, regardless of prefix, being interpreted as non-switch
|
||||
// arguments. Switch names are considered case-insensitive. This class can be
|
||||
// used before CefInitialize() is called.
|
||||
// arguments. Switch names should be lowercase ASCII and will be converted to
|
||||
// such if necessary. Switch values will retain the original case and UTF8
|
||||
// encoding. This class can be used before CefInitialize() is called.
|
||||
///
|
||||
/*--cef(source=library,no_debugct_check)--*/
|
||||
class CefCommandLine : public virtual CefBaseRefCounted {
|
||||
|
|
|
@ -6,6 +6,7 @@
|
|||
|
||||
#include "base/files/file_path.h"
|
||||
#include "base/logging.h"
|
||||
#include "base/strings/string_util.h"
|
||||
|
||||
CefCommandLineImpl::CefCommandLineImpl(base::CommandLine* value,
|
||||
bool will_delete,
|
||||
|
@ -90,12 +91,13 @@ bool CefCommandLineImpl::HasSwitches() {
|
|||
|
||||
bool CefCommandLineImpl::HasSwitch(const CefString& name) {
|
||||
CEF_VALUE_VERIFY_RETURN(false, false);
|
||||
return const_value().HasSwitch(name.ToString());
|
||||
return const_value().HasSwitch(base::ToLowerASCII(name.ToString()));
|
||||
}
|
||||
|
||||
CefString CefCommandLineImpl::GetSwitchValue(const CefString& name) {
|
||||
CEF_VALUE_VERIFY_RETURN(false, CefString());
|
||||
return const_value().GetSwitchValueNative(name.ToString());
|
||||
return const_value().GetSwitchValueNative(
|
||||
base::ToLowerASCII(name.ToString()));
|
||||
}
|
||||
|
||||
void CefCommandLineImpl::GetSwitches(SwitchMap& switches) {
|
||||
|
|
|
@ -483,6 +483,11 @@ patches = [
|
|||
# https://bitbucket.org/chromiumembedded/cef/issues/123
|
||||
'name': 'print_preview_123',
|
||||
},
|
||||
{
|
||||
# Store command-line switch names as lower-case ASCII on all platforms.
|
||||
# https://bitbucket.org/chromiumembedded/cef/issues/1872
|
||||
'name': 'base_command_line_1872',
|
||||
},
|
||||
{
|
||||
# Remove cef_sandbox dependency on boringssl MD5/SHA1 functions.
|
||||
# https://bitbucket.org/chromiumembedded/cef/issues/2743
|
||||
|
|
|
@ -0,0 +1,17 @@
|
|||
diff --git base/command_line.cc base/command_line.cc
|
||||
index 3ef2e87e40687..f7b91a202a377 100644
|
||||
--- base/command_line.cc
|
||||
+++ base/command_line.cc
|
||||
@@ -333,11 +333,10 @@ void CommandLine::AppendSwitchPath(StringPiece switch_string,
|
||||
|
||||
void CommandLine::AppendSwitchNative(StringPiece switch_string,
|
||||
CommandLine::StringPieceType value) {
|
||||
-#if defined(OS_WIN)
|
||||
const std::string switch_key = ToLowerASCII(switch_string);
|
||||
+#if defined(OS_WIN)
|
||||
StringType combined_switch_string(UTF8ToWide(switch_key));
|
||||
#elif defined(OS_POSIX) || defined(OS_FUCHSIA)
|
||||
- StringPiece switch_key = switch_string;
|
||||
StringType combined_switch_string(switch_key);
|
||||
#endif
|
||||
size_t prefix_length = GetSwitchPrefixLength(combined_switch_string);
|
|
@ -18,9 +18,10 @@ void VerifyCommandLine(CefRefPtr<CefCommandLine> command_line,
|
|||
EXPECT_TRUE(command_line->HasSwitch("switch1"));
|
||||
std::string switch1 = command_line->GetSwitchValue("switch1");
|
||||
EXPECT_EQ("", switch1);
|
||||
EXPECT_TRUE(command_line->HasSwitch("switch2"));
|
||||
std::string switch2 = command_line->GetSwitchValue("switch2");
|
||||
EXPECT_EQ("val2", switch2);
|
||||
// Switch names are converted to lowercase but values are left unchanged.
|
||||
EXPECT_TRUE(command_line->HasSwitch("SWITCH2"));
|
||||
std::string switch2 = command_line->GetSwitchValue("SWITCH2");
|
||||
EXPECT_EQ("VAL2", switch2);
|
||||
EXPECT_TRUE(command_line->HasSwitch("switch3"));
|
||||
std::string switch3 = command_line->GetSwitchValue("switch3");
|
||||
EXPECT_EQ("val3", switch3);
|
||||
|
@ -45,7 +46,7 @@ void VerifyCommandLine(CefRefPtr<CefCommandLine> command_line,
|
|||
EXPECT_EQ("", val);
|
||||
} else if (name == "switch2") {
|
||||
has2 = true;
|
||||
EXPECT_EQ("val2", val);
|
||||
EXPECT_EQ("VAL2", val);
|
||||
} else if (name == "switch3") {
|
||||
has3 = true;
|
||||
EXPECT_EQ("val3", val);
|
||||
|
@ -86,10 +87,10 @@ TEST(CommandLineTest, Init) {
|
|||
|
||||
#if defined(OS_WIN)
|
||||
command_line->InitFromString(
|
||||
"test.exe --switch1 -switch2=val2 /switch3=val3 "
|
||||
"test.exe --switch1 -switch2=VAL2 /switch3=val3 "
|
||||
"-switch4=\"val 4\" arg1 \"arg 2\"");
|
||||
#else
|
||||
const char* args[] = {"test.exe", "--switch1", "-switch2=val2",
|
||||
const char* args[] = {"test.exe", "--switch1", "-switch2=VAL2",
|
||||
"-switch3=val3", "-switch4=val 4", "arg1",
|
||||
"arg 2"};
|
||||
command_line->InitFromArgv(sizeof(args) / sizeof(char*), args);
|
||||
|
@ -105,7 +106,7 @@ TEST(CommandLineTest, Manual) {
|
|||
|
||||
command_line->SetProgram("test.exe");
|
||||
command_line->AppendSwitch("switch1");
|
||||
command_line->AppendSwitchWithValue("switch2", "val2");
|
||||
command_line->AppendSwitchWithValue("switch2", "VAL2");
|
||||
command_line->AppendSwitchWithValue("switch3", "val3");
|
||||
command_line->AppendSwitchWithValue("switch4", "val 4");
|
||||
command_line->AppendArgument("arg1");
|
||||
|
@ -121,7 +122,7 @@ TEST(CommandLineTest, IgnorePrefixes) {
|
|||
|
||||
command_line->SetProgram("test.exe");
|
||||
command_line->AppendSwitch("-switch1");
|
||||
command_line->AppendSwitchWithValue("--switch2", "val2");
|
||||
command_line->AppendSwitchWithValue("--switch2", "VAL2");
|
||||
command_line->AppendSwitchWithValue("-switch3", "val3");
|
||||
command_line->AppendSwitchWithValue("-switch4", "val 4");
|
||||
|
||||
|
@ -133,3 +134,19 @@ TEST(CommandLineTest, IgnorePrefixes) {
|
|||
|
||||
VerifyCommandLine(command_line, arg1, arg2);
|
||||
}
|
||||
|
||||
// Test that command line switch names are converted to lowercase ASCII.
|
||||
TEST(CommandLineTest, IgnoreCase) {
|
||||
CefRefPtr<CefCommandLine> command_line = CefCommandLine::CreateCommandLine();
|
||||
EXPECT_TRUE(command_line.get() != nullptr);
|
||||
|
||||
command_line->SetProgram("test.exe");
|
||||
command_line->AppendSwitch("-Switch1");
|
||||
command_line->AppendSwitchWithValue("-SWITCH2", "VAL2");
|
||||
command_line->AppendSwitchWithValue("-switch3", "val3");
|
||||
command_line->AppendSwitchWithValue("-switch4", "val 4");
|
||||
command_line->AppendArgument("arg1");
|
||||
command_line->AppendArgument("arg 2");
|
||||
|
||||
VerifyCommandLine(command_line);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue