Take the words after double dash as operands without a flag, and drop an empty glob

This commit is contained in:
2026-11-13 21:54:34 +01:00
parent e0c8209750
commit 26f5ccde78
2 changed files with 13 additions and 9 deletions
+12 -8
View File
@@ -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.""" """A search's arguments as its options and its operands: the words after `--` are operands."""
options: list[str] = [] options: list[str] = []
operands: list[str] = [] operands: list[str] = []
ended = False words = iter(arguments)
for word in arguments: for word in words:
if ended or not word.startswith("-"): if word == "--":
operands.append(word) # It takes the rest of the words, which ends the loop.
elif word == "--": operands.extend(words)
ended = True elif word.startswith("-"):
else:
options.append(word) options.append(word)
else:
operands.append(word)
return options, operands return options, operands
@@ -127,7 +128,10 @@ def globs_of(arguments: list[str]) -> list[str]:
option = GLOB_OPTION.fullmatch(word) option = GLOB_OPTION.fullmatch(word)
if option: if option:
given = option.group(1) or option.group(2) 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 return found
+1 -1
View File
@@ -535,7 +535,7 @@ class EnvFileRead(unittest.TestCase):
self.assertEqual(self.breached("Bash", {"command": command}), expected) self.assertEqual(self.breached("Bash", {"command": command}), expected)
def test_rg_searches_only_the_files_a_positive_glob_matches(self): 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): with self.subTest(command):
self.assertEqual(self.breached("Bash", {"command": command}), expected) self.assertEqual(self.breached("Bash", {"command": command}), expected)