command_line_args.cc 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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 "atom/app/command_line_args.h"
  5. namespace {
  6. bool IsUrlArg(const base::CommandLine::CharType* arg) {
  7. // the first character must be a letter for this to be a URL
  8. auto c = *arg;
  9. if (('a' <= c && c <= 'z') || ('A' <= c && c <= 'Z')) {
  10. for (auto* p = arg + 1; *p; ++p) {
  11. c = *p;
  12. // colon indicates that the argument starts with a URI scheme
  13. if (c == ':') {
  14. // it could also be a Windows filesystem path
  15. if (p == arg + 1)
  16. break;
  17. return true;
  18. }
  19. // white-space before a colon means it's not a URL
  20. if (c == ' ' || (0x9 <= c && c <= 0xD))
  21. break;
  22. }
  23. }
  24. return false;
  25. }
  26. } // namespace
  27. namespace atom {
  28. bool CheckCommandLineArguments(int argc, base::CommandLine::CharType** argv) {
  29. const base::CommandLine::StringType dashdash(2, '-');
  30. bool block_args = false;
  31. for (int i = 0; i < argc; ++i) {
  32. if (argv[i] == dashdash)
  33. break;
  34. if (block_args) {
  35. return false;
  36. } else if (IsUrlArg(argv[i])) {
  37. block_args = true;
  38. }
  39. }
  40. return true;
  41. }
  42. } // namespace atom