[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
master ecb9641ecb5 2/3: Support more complex env invocations in shebang
From: |
Eli Zaretskii |
Subject: |
master ecb9641ecb5 2/3: Support more complex env invocations in shebang lines |
Date: |
Sat, 17 Feb 2024 03:32:50 -0500 (EST) |
branch: master
commit ecb9641ecb5f42899042ff9c164ec7dbb8e166fe
Author: Kévin Le Gouguec <kevin.legouguec@gmail.com>
Commit: Eli Zaretskii <eliz@gnu.org>
Support more complex env invocations in shebang lines
This is not an exact re-implementation of what env accepts, but
hopefully it should be "good enough".
Example of known limitation: we assume that arguments for
--long-options will be set with '=', but that is not
necessarily the case. '--unset' (mandatory argument) can be
passed as '--unset=VAR' or '--unset VAR', but
'--default-signal' (optional argument) requires an '=' sign.
For bug#64939.
* lisp/files.el (auto-mode-interpreter-regexp): Account for
supplementary arguments passed beside -S/--split-string.
* test/lisp/files-tests.el (files-tests-auto-mode-interpreter):
Test some of these combinations.
---
lisp/files.el | 8 +++++++-
test/lisp/files-tests.el | 8 +++++++-
2 files changed, 14 insertions(+), 2 deletions(-)
diff --git a/lisp/files.el b/lisp/files.el
index f67b650cb92..5098d49048e 100644
--- a/lisp/files.el
+++ b/lisp/files.el
@@ -3274,7 +3274,13 @@ and `inhibit-local-variables-suffixes'. If
;; Optional group 1: env(1) invocation.
"\\("
"[^ \t\n]*/bin/env[ \t]*"
- "\\(?:-S[ \t]*\\|--split-string\\(?:=\\|[ \t]*\\)\\)?"
+ ;; Within group 1: possible -S/--split-string.
+ "\\(?:"
+ ;; -S/--split-string
+ "\\(?:-[0a-z]*S[ \t]*\\|--split-string=\\)"
+ ;; More env arguments.
+ "\\(?:-[^ \t\n]+[ \t]+\\)*"
+ "\\)?"
"\\)?"
;; Group 2: interpreter.
"\\([^ \t\n]+\\)"))
diff --git a/test/lisp/files-tests.el b/test/lisp/files-tests.el
index 23516ff0d7d..0a5c3b897e4 100644
--- a/test/lisp/files-tests.el
+++ b/test/lisp/files-tests.el
@@ -1687,8 +1687,14 @@ set to."
(files-tests--check-shebang "#!/usr/bin/env python" 'python-base-mode)
(files-tests--check-shebang "#!/usr/bin/env python3" 'python-base-mode)
;; Invocation through env, with supplementary arguments.
+ (files-tests--check-shebang "#!/usr/bin/env --split-string=bash -eux"
'sh-base-mode 'bash)
+ (files-tests--check-shebang "#!/usr/bin/env --split-string=-iv
--default-signal bash -eux" 'sh-base-mode 'bash)
(files-tests--check-shebang "#!/usr/bin/env -S awk -v FS=\"\\t\" -v
OFS=\"\\t\" -f" 'awk-mode)
- (files-tests--check-shebang "#!/usr/bin/env -S make -f" 'makefile-mode))
+ (files-tests--check-shebang "#!/usr/bin/env -S make -f" 'makefile-mode)
+ (files-tests--check-shebang "#!/usr/bin/env -S-vi bash -eux" 'sh-base-mode
'bash)
+ (files-tests--check-shebang "#!/usr/bin/env -ivS --default-signal=INT bash
-eux" 'sh-base-mode 'bash)
+ (files-tests--check-shebang "#!/usr/bin/env -ivS --default-signal bash -eux"
'sh-base-mode 'bash)
+ (files-tests--check-shebang "#!/usr/bin/env -vS -uFOOBAR bash -eux"
'sh-base-mode 'bash))
(ert-deftest files-test-dir-locals-auto-mode-alist ()
"Test an `auto-mode-alist' entry in `.dir-locals.el'"