2018-01-22 22:49:30 +00:00
|
|
|
// Copyright (c) 2018 GitHub, Inc.
|
|
|
|
// Use of this source code is governed by the MIT license that can be
|
|
|
|
// found in the LICENSE file.
|
|
|
|
|
2019-06-19 20:46:59 +00:00
|
|
|
#include "shell/app/command_line_args.h"
|
2021-06-14 12:01:00 +00:00
|
|
|
#include <locale>
|
2018-01-22 22:49:30 +00:00
|
|
|
|
|
|
|
namespace {
|
|
|
|
|
|
|
|
bool IsUrlArg(const base::CommandLine::CharType* arg) {
|
|
|
|
// the first character must be a letter for this to be a URL
|
|
|
|
auto c = *arg;
|
2021-06-14 12:01:00 +00:00
|
|
|
if (std::isalpha(c, std::locale::classic())) {
|
2018-04-17 22:41:47 +00:00
|
|
|
for (auto* p = arg + 1; *p; ++p) {
|
2018-01-22 22:49:30 +00:00
|
|
|
c = *p;
|
|
|
|
|
|
|
|
// colon indicates that the argument starts with a URI scheme
|
|
|
|
if (c == ':') {
|
|
|
|
// it could also be a Windows filesystem path
|
|
|
|
if (p == arg + 1)
|
|
|
|
break;
|
|
|
|
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
|
|
|
// white-space before a colon means it's not a URL
|
2021-06-14 12:01:00 +00:00
|
|
|
if (std::isspace(c, std::locale::classic()))
|
2018-01-22 22:49:30 +00:00
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
namespace electron {
|
2018-01-22 22:49:30 +00:00
|
|
|
|
|
|
|
bool CheckCommandLineArguments(int argc, base::CommandLine::CharType** argv) {
|
|
|
|
const base::CommandLine::StringType dashdash(2, '-');
|
2018-05-22 16:51:03 +00:00
|
|
|
bool block_args = false;
|
2018-01-22 22:49:30 +00:00
|
|
|
for (int i = 0; i < argc; ++i) {
|
|
|
|
if (argv[i] == dashdash)
|
|
|
|
break;
|
2018-05-22 16:51:03 +00:00
|
|
|
if (block_args) {
|
|
|
|
return false;
|
2018-01-22 22:49:30 +00:00
|
|
|
} else if (IsUrlArg(argv[i])) {
|
2018-05-22 16:51:03 +00:00
|
|
|
block_args = true;
|
2018-01-22 22:49:30 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return true;
|
|
|
|
}
|
|
|
|
|
2019-06-19 21:23:04 +00:00
|
|
|
} // namespace electron
|