From 26f5ccde78b9dc8c3331073dec1e8c1783d63847 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Fri, 13 Nov 2026 21:54:34 +0100 Subject: [PATCH] Take the words after double dash as operands without a flag, and drop an empty glob --- bin/rule_hook/env_file.py | 20 ++++++++++++-------- bin/rule_hook/test_rule_hook.py | 2 +- 2 files changed, 13 insertions(+), 9 deletions(-) diff --git a/bin/rule_hook/env_file.py b/bin/rule_hook/env_file.py index 9dd15770..013edd1f 100644 --- a/bin/rule_hook/env_file.py +++ b/bin/rule_hook/env_file.py @@ -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 diff --git a/bin/rule_hook/test_rule_hook.py b/bin/rule_hook/test_rule_hook.py index dd81f2fb..2e92c121 100644 --- a/bin/rule_hook/test_rule_hook.py +++ b/bin/rule_hook/test_rule_hook.py @@ -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)