Take the words after double dash as operands without a flag, and drop an empty glob
This commit is contained in:
@@ -99,14 +99,15 @@ def split(arguments: list[str]) -> tuple[list[str], list[str]]:
|
||||
"""A search's arguments as its options and its operands: the words after `--` are operands."""
|
||||
options: list[str] = []
|
||||
operands: list[str] = []
|
||||
ended = False
|
||||
for word in arguments:
|
||||
if ended or not word.startswith("-"):
|
||||
operands.append(word)
|
||||
elif word == "--":
|
||||
ended = True
|
||||
else:
|
||||
words = iter(arguments)
|
||||
for word in words:
|
||||
if word == "--":
|
||||
# It takes the rest of the words, which ends the loop.
|
||||
operands.extend(words)
|
||||
elif word.startswith("-"):
|
||||
options.append(word)
|
||||
else:
|
||||
operands.append(word)
|
||||
return options, operands
|
||||
|
||||
|
||||
@@ -127,7 +128,10 @@ def globs_of(arguments: list[str]) -> list[str]:
|
||||
option = GLOB_OPTION.fullmatch(word)
|
||||
if option:
|
||||
given = option.group(1) or option.group(2)
|
||||
found.append(given if given else arguments[at + 1] if at + 1 < len(arguments) else "")
|
||||
if not given and at + 1 < len(arguments):
|
||||
given = arguments[at + 1]
|
||||
if given:
|
||||
found.append(given)
|
||||
return found
|
||||
|
||||
|
||||
|
||||
@@ -535,7 +535,7 @@ class EnvFileRead(unittest.TestCase):
|
||||
self.assertEqual(self.breached("Bash", {"command": command}), expected)
|
||||
|
||||
def test_rg_searches_only_the_files_a_positive_glob_matches(self):
|
||||
for command, expected in (("rg -g '*.md' TOKEN ~/secrets", []), ("rg -g '*.md' -g '*.env' TOKEN ~/secrets", ["env-file-read"]), ("rg -g '!*.md' TOKEN ~/secrets", ["env-file-read"]), ("rg -ng '*.md' TOKEN ~/secrets", []), ("rg --glob '*.md' TOKEN ~/secrets", []), ("rg --iglob '*.md' TOKEN ~/secrets", []), ("rg TOKEN ~/secrets -g", [])):
|
||||
for command, expected in (("rg -g '*.md' TOKEN ~/secrets", []), ("rg -g '*.md' -g '*.env' TOKEN ~/secrets", ["env-file-read"]), ("rg -g '!*.md' TOKEN ~/secrets", ["env-file-read"]), ("rg -ng '*.md' TOKEN ~/secrets", []), ("rg --glob '*.md' TOKEN ~/secrets", []), ("rg --iglob '*.md' TOKEN ~/secrets", []), ("rg TOKEN ~/secrets -g", ["env-file-read"]), ("rg TOKEN ~/secrets -g '*.env'", ["env-file-read"]), ("rg TOKEN ~/secrets -g '*.md'", [])):
|
||||
with self.subTest(command):
|
||||
self.assertEqual(self.breached("Bash", {"command": command}), expected)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user