From 16b1ffc05efd8faa034bf9039ad6f9aecb388296 Mon Sep 17 00:00:00 2001 From: Lilleman auf Larv Date: Thu, 22 Oct 2026 12:59:05 +0200 Subject: [PATCH] =?UTF-8?q?Answer=20stability=20round=202:=200=20?= =?UTF-8?q?=F0=9F=94=B4,=201=20=F0=9F=9F=A1;=20drop=20the=20two=20tests=20?= =?UTF-8?q?that=20asserted=20a=20misparse=20of=20process=20substitution?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- bin/rule_hook/test_rule_hook.py | 3 +-- bin/shell_command.py | 5 ++--- 2 files changed, 3 insertions(+), 5 deletions(-) diff --git a/bin/rule_hook/test_rule_hook.py b/bin/rule_hook/test_rule_hook.py index d480c610..ec245253 100644 --- a/bin/rule_hook/test_rule_hook.py +++ b/bin/rule_hook/test_rule_hook.py @@ -85,10 +85,9 @@ class Commits(unittest.TestCase): def test_a_separator_glued_to_a_redirect_still_ends_the_command(self): self.assertEqual(segments("echo a > f; echo b | cat &> g\nls"), [["echo", "a"], ["echo", "b"], ["cat"], ["ls"]]) - for command in ["echo a &f git commit -m hi", "tee >(true) git commit -m hi"]: + for command in ["echo a &f git commit -m hi"]: with self.subTest(command): self.assertEqual(committed(command), [Commit("/r", ["hi"], False)]) - self.assertEqual(segments("diff <(a) b"), [["diff"], ["b"]]) class CommandBreaches(unittest.TestCase): diff --git a/bin/shell_command.py b/bin/shell_command.py index 5e85780a..294bd554 100644 --- a/bin/shell_command.py +++ b/bin/shell_command.py @@ -7,7 +7,7 @@ import shlex HEREDOC = re.compile(r"<<-?[ \t]*([\"']?)([A-Za-z_]\w*)\1[^\n]*\n.*?^[ \t]*\2[ \t]*$", re.DOTALL | re.MULTILINE) ASSIGNMENT = re.compile(r"[A-Za-z_][A-Za-z0-9_]*=") OPERATOR = set("\n();&|<>") -# A redirect operator on its own: a command goes on around it. `&<` is no redirect: it is a `&` that ends the command, then a `<`. +# A token that is only a redirect: the command's words go on after its target. `&<` is not one: it is a `&` that ends the command, then a `<`. REDIRECT = re.compile(r"&>>?|[<>]+[&|]?") # A quoted string or an escape is taken whole, so a # inside one starts no comment; a comment starts a word. PIECE = re.compile(r"""'[^']*'|"(?:\\.|[^"\\])*"|\\.|(? list[list[str]]: - a quoted string is one word, so `bash -c "git commit"` and `echo "$(git commit)"` hide the inner command; - a backtick substitution stays inside its words, while `$(git commit)` outside quotes splits into the `$` and a command of its own; - a keyword or a brace opens its command's words, so `then git commit` reads as the command `then`; - - `<(...)` and `>(...)` end the command, and the word after them is dropped as a redirect target, so `tee >(git commit)` hides the commit; - - `<<<` reads as a redirect, so the word after it is dropped as the target; + - `<(...)` and `>(...)` end the command, and the first word inside them is dropped as a redirect target, so `tee >(git commit)` hides the commit; - a file descriptor before a redirect, as in `2>&1`, stays a word; - a heredoc's body is dropped; - variables, aliases and functions are not expanded;