command_line_args.cc 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. // Copyright (c) 2018 GitHub, Inc.
  2. // Use of this source code is governed by the MIT license that can be
  3. // found in the LICENSE file.
  4. #include "shell/app/command_line_args.h"
  5. #include <locale>
  6. namespace {
  7. bool IsUrlArg(const base::CommandLine::CharType* arg) {
  8. // the first character must be a letter for this to be a URL
  9. auto c = *arg;
  10. if (std::isalpha(c, std::locale::classic())) {
  11. for (auto* p = arg + 1; *p; ++p) {
  12. c = *p;
  13. // colon indicates that the argument starts with a URI scheme
  14. if (c == ':') {
  15. // it could also be a Windows filesystem path
  16. if (p == arg + 1)
  17. break;
  18. return true;
  19. }
  20. // white-space before a colon means it's not a URL
  21. if (std::isspace(c, std::locale::classic()))
  22. break;
  23. }
  24. }
  25. return false;
  26. }
  27. } // namespace
  28. namespace electron {
  29. bool CheckCommandLineArguments(int argc, base::CommandLine::CharType** argv) {
  30. const base::CommandLine::StringType dashdash(2, '-');
  31. bool block_args = false;
  32. for (int i = 0; i < argc; ++i) {
  33. if (argv[i] == dashdash)
  34. break;
  35. if (block_args) {
  36. return false;
  37. } else if (IsUrlArg(argv[i])) {
  38. block_args = true;
  39. }
  40. }
  41. return true;
  42. }
  43. } // namespace electron