From ce361a12e355f9e1e99c989f1ea056c9e502dbe7 Mon Sep 17 00:00:00 2001 From: Samuel Attard Date: Wed, 31 Jan 2018 17:35:09 -0700 Subject: [PATCH 1/5] Use case-insensitive switch comparisons --- atom/app/command_line_args.cc | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/atom/app/command_line_args.cc b/atom/app/command_line_args.cc index d7426de7dc..e83eed46f2 100644 --- a/atom/app/command_line_args.cc +++ b/atom/app/command_line_args.cc @@ -1390,7 +1390,8 @@ bool IsBlacklistedArg(const base::CommandLine::CharType* arg) { if (prefix_length > 0) { a += prefix_length; - std::string switch_name(a, strcspn(a, "=")); + std::string switch_name = + base::ToLowerASCII(base::StringPiece(a, strcspn(a, "="))); auto* iter = std::lower_bound(std::begin(kBlacklist), std::end(kBlacklist), switch_name); if (iter != std::end(kBlacklist) && switch_name == *iter) { From 8405fe763e25d2cd0be22b87ddb41248671cbc68 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 31 Jan 2018 17:35:34 -0700 Subject: [PATCH 2/5] Make a copy-paste recipe for rebuilding the blacklist --- atom/app/command_line_args.cc | 32 ++++++++++++++------------------ 1 file changed, 14 insertions(+), 18 deletions(-) diff --git a/atom/app/command_line_args.cc b/atom/app/command_line_args.cc index e83eed46f2..5f0dacd90b 100644 --- a/atom/app/command_line_args.cc +++ b/atom/app/command_line_args.cc @@ -38,24 +38,20 @@ bool IsUrlArg(const base::CommandLine::CharType* arg) { return false; } -// The blacklist of command line switches, must be sorted. -// Created with: -// find ./ -name "*switches.cc" \ -// | xargs grep -P --no-filename "\"\S+\";" \ -// | perl -pe 's|^.*?"(\S+)";| "$1",|' \ -// | sort | uniq -// then manually insert following switches into the list: -// "inspect", -// "inspect-brk", -// finally write a small piece of code to print out the sorted list since -// the "sort" tool may use differnt rules from C++ STL. -// std::vector sorted(std::begin(kBlacklist), -// std::end(kBlacklist)); -// std::sort(sorted.begin(), sorted.end()); -// FILE* f = fopen("testlist2", "w+"); -// for (auto& i : sorted) -// fprintf(f, "\"%s\",\n", i.c_str()); -// fclose(f); +/* + * The blacklist of command line switches, must be sorted. + * Update the list by pasting the following command into bash + * in libchromiumcontent/src/: + + (find ./ -name "*switches.cc" | \ + xargs grep -P --no-filename "\"\S+\";" | \ + perl -pe 's|^.*?"(\S+)";| "$1",|'; \ + echo ' "inspect",'; \ + echo ' "inspect-brk",') | \ + LANG=C sort | \ + uniq > blacklist-switches.txt + + */ const char* kBlacklist[] = { "/prefetch:1", "/prefetch:2", From 09a2c804439f73adb32c81631ad9b354a72ba3e0 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 31 Jan 2018 17:36:06 -0700 Subject: [PATCH 3/5] use std::binary_search to search switch blacklist --- atom/app/command_line_args.cc | 12 ++++-------- 1 file changed, 4 insertions(+), 8 deletions(-) diff --git a/atom/app/command_line_args.cc b/atom/app/command_line_args.cc index 5f0dacd90b..d60816a84d 100644 --- a/atom/app/command_line_args.cc +++ b/atom/app/command_line_args.cc @@ -1388,11 +1388,8 @@ bool IsBlacklistedArg(const base::CommandLine::CharType* arg) { a += prefix_length; std::string switch_name = base::ToLowerASCII(base::StringPiece(a, strcspn(a, "="))); - auto* iter = std::lower_bound(std::begin(kBlacklist), std::end(kBlacklist), - switch_name); - if (iter != std::end(kBlacklist) && switch_name == *iter) { - return true; - } + return std::lower_bound(std::begin(kBlacklist), std::end(kBlacklist), + switch_name); } return false; @@ -1408,9 +1405,8 @@ bool CheckCommandLineArguments(int argc, base::CommandLine::CharType** argv) { return base::StringPiece(a) < base::StringPiece(b); })) << "The kBlacklist must be in sorted order"; - DCHECK_NE(std::find(std::begin(kBlacklist), std::end(kBlacklist), - base::StringPiece("inspect")), - std::end(kBlacklist)) + DCHECK_NE(std::binary_search(std::begin(kBlacklist), std::end(kBlacklist), + base::StringPiece("inspect")); << "Do not forget to add Node command line flags to kBlacklist"; const base::CommandLine::StringType dashdash(2, '-'); From 1106cde687bee3f9098a4476d2933cfacea166c7 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 31 Jan 2018 17:40:11 -0700 Subject: [PATCH 4/5] fix oops --- atom/app/command_line_args.cc | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/atom/app/command_line_args.cc b/atom/app/command_line_args.cc index d60816a84d..f3d47a5264 100644 --- a/atom/app/command_line_args.cc +++ b/atom/app/command_line_args.cc @@ -1388,8 +1388,8 @@ bool IsBlacklistedArg(const base::CommandLine::CharType* arg) { a += prefix_length; std::string switch_name = base::ToLowerASCII(base::StringPiece(a, strcspn(a, "="))); - return std::lower_bound(std::begin(kBlacklist), std::end(kBlacklist), - switch_name); + return std::binary_search(std::begin(kBlacklist), std::end(kBlacklist), + switch_name); } return false; From e51c78f10c472156ed47cea227658838fba646a4 Mon Sep 17 00:00:00 2001 From: Charles Kerr Date: Wed, 31 Jan 2018 22:25:57 -0700 Subject: [PATCH 5/5] fix oops because compiling before pushing is for wusses --- atom/app/command_line_args.cc | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/atom/app/command_line_args.cc b/atom/app/command_line_args.cc index f3d47a5264..9472d1cb9f 100644 --- a/atom/app/command_line_args.cc +++ b/atom/app/command_line_args.cc @@ -1405,9 +1405,9 @@ bool CheckCommandLineArguments(int argc, base::CommandLine::CharType** argv) { return base::StringPiece(a) < base::StringPiece(b); })) << "The kBlacklist must be in sorted order"; - DCHECK_NE(std::binary_search(std::begin(kBlacklist), std::end(kBlacklist), - base::StringPiece("inspect")); - << "Do not forget to add Node command line flags to kBlacklist"; + DCHECK(std::binary_search(std::begin(kBlacklist), std::end(kBlacklist), + base::StringPiece("inspect"))) + << "Remember to add Node command line flags to kBlacklist"; const base::CommandLine::StringType dashdash(2, '-'); bool block_blacklisted_args = false;