Merge pull request #2145 from avdv/fix-2143

Allow `env` to have flags and variables in shebang
This commit is contained in:
Vidar Holen 2021-02-22 21:00:04 -08:00 committed by GitHub
commit 670c1de01b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 4 additions and 2 deletions

View File

@ -3190,6 +3190,7 @@ prop_readScript2 = isWarning readScript "#!/bin/bash\r\necho hello world\n"
prop_readScript3 = isWarning readScript "#!/bin/bash\necho hello\xA0world" prop_readScript3 = isWarning readScript "#!/bin/bash\necho hello\xA0world"
prop_readScript4 = isWarning readScript "#!/usr/bin/perl\nfoo=(" prop_readScript4 = isWarning readScript "#!/usr/bin/perl\nfoo=("
prop_readScript5 = isOk readScript "#!/bin/bash\n#This is an empty script\n\n" prop_readScript5 = isOk readScript "#!/bin/bash\n#This is an empty script\n\n"
prop_readScript6 = isOk readScript "#!/usr/bin/env -S X=FOO bash\n#This is an empty script\n\n"
readScriptFile sourced = do readScriptFile sourced = do
start <- startSpan start <- startSpan
pos <- getPosition pos <- getPosition
@ -3231,13 +3232,14 @@ readScriptFile sourced = do
where where
basename s = reverse . takeWhile (/= '/') . reverse $ s basename s = reverse . takeWhile (/= '/') . reverse $ s
skipFlags = dropWhile ("-" `isPrefixOf`)
getShell sb = getShell sb =
case words sb of case words sb of
[] -> "" [] -> ""
[x] -> basename x [x] -> basename x
(first:second:_) -> (first:args) ->
if basename first == "env" if basename first == "env"
then second then fromMaybe "" $ find (notElem '=') $ skipFlags args
else basename first else basename first
verifyShebang pos s = do verifyShebang pos s = do