From 59094e944b4a9e8c5e1a20724c2681ffe9b6155c Mon Sep 17 00:00:00 2001 From: Craig Jennings Date: Sun, 3 May 2026 19:44:05 -0500 Subject: fix: shell-quote F6 test-runner command arguments `cj/--f6-test-runner-cmd-for` was building shell command strings with raw paths and stems via `format`. For ordinary names (`tests/test_foo.py`, `pkg/foo`) that worked fine. But a path with spaces or a stem with shell metacharacters would break or misbehave once the string hit `compile`. A Python test file under `dir with spaces/` would get tokenized as separate arguments. I added `cj/--f6-shell-quote-argument` that escapes only when the argument doesn't match `cj/--f6-shell-safe-argument-regexp` (alphanumerics, slash, dot, dash, plus a small handful of safe punctuation). Ordinary paths skip the quoter and stay readable. Risky paths route through `shell-quote-argument`. I wrapped the four interpolations in the test-runner builder: the elisp `FILE=` basename, the elisp `TEST=^test-stem-` regex, both pytest paths, and the Go `./rel-dir`. The Go branch also handles an empty rel-dir explicitly so the result stays `go test ./` instead of constructing `./` via format with an empty string. I added three boundary tests: a Python path with spaces, an elisp stem with `;`, and a Go directory with spaces. Existing tests for ordinary paths continue to pass since the safe regex covers them. --- tests/test-dev-fkeys--f6-test-runner-cmd-for.el | 21 +++++++++++++++++++++ 1 file changed, 21 insertions(+) (limited to 'tests') diff --git a/tests/test-dev-fkeys--f6-test-runner-cmd-for.el b/tests/test-dev-fkeys--f6-test-runner-cmd-for.el index cb242889..36f97548 100644 --- a/tests/test-dev-fkeys--f6-test-runner-cmd-for.el +++ b/tests/test-dev-fkeys--f6-test-runner-cmd-for.el @@ -95,6 +95,27 @@ would over-match. Pass just the basename — the Makefile re-prepends 'go nil "main.go" "main" "") "go test ./"))) +(ert-deftest test-dev-fkeys-f6-cmd-for-python-test-file-quotes-spaces () + "Boundary: a Python test file path with spaces is shell-escaped." + (should (string= + (cj/--f6-test-runner-cmd-for + 'python t "tests/dir with spaces/test_foo.py" "foo" "tests/dir with spaces") + "pytest tests/dir\\ with\\ spaces/test_foo.py"))) + +(ert-deftest test-dev-fkeys-f6-cmd-for-elisp-source-quotes-test-regex () + "Boundary: an elisp source stem with shell metacharacters is escaped." + (should (string= + (cj/--f6-test-runner-cmd-for + 'elisp nil "modules/foo;bar.el" "foo;bar" "modules") + "make test-name TEST=\\^test-foo\\;bar-"))) + +(ert-deftest test-dev-fkeys-f6-cmd-for-go-source-quotes-spaces () + "Boundary: a Go package path with spaces is shell-escaped." + (should (string= + (cj/--f6-test-runner-cmd-for + 'go nil "pkg/with spaces/foo.go" "foo" "pkg/with spaces") + "go test ./pkg/with\\ spaces"))) + ;;; Error Cases (ert-deftest test-dev-fkeys-f6-cmd-for-typescript-returns-nil () -- cgit v1.2.3