mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-11 07:36:29 -07:00
Treat $x/ or $(x)/ as ./ when finding sourced files (fixes #1998)
This commit is contained in:
parent
1b884a17ea
commit
210cdcd01a
4 changed files with 25 additions and 1 deletions
|
@ -2122,7 +2122,7 @@ readSource t@(T_Redirecting _ _ (T_SimpleCommand cmdId _ (cmd:file':rest'))) = d
|
|||
let file = getFile file' rest'
|
||||
override <- getSourceOverride
|
||||
let literalFile = do
|
||||
name <- override `mplus` getLiteralString file
|
||||
name <- override `mplus` getLiteralString file `mplus` stripDynamicPrefix file
|
||||
-- Hack to avoid 'source ~/foo' trying to read from literal tilde
|
||||
guard . not $ "~/" `isPrefixOf` name
|
||||
return name
|
||||
|
@ -2182,6 +2182,16 @@ readSource t@(T_Redirecting _ _ (T_SimpleCommand cmdId _ (cmd:file':rest'))) = d
|
|||
SourcePath x -> Just x
|
||||
_ -> Nothing
|
||||
|
||||
-- If the word has a single expansion as the directory, try stripping it
|
||||
-- This affects `$foo/bar` but not `${foo}-dir/bar` or `/foo/$file`
|
||||
stripDynamicPrefix word =
|
||||
case getWordParts word of
|
||||
exp : rest | isStringExpansion exp -> do
|
||||
str <- getLiteralString (T_NormalWord (Id 0) rest)
|
||||
guard $ "/" `isPrefixOf` str
|
||||
return $ "." ++ str
|
||||
_ -> Nothing
|
||||
|
||||
subRead name script =
|
||||
withContext (ContextSource name) $
|
||||
inSeparateContext $
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue