mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-12 08:06:29 -07:00
Add handling for special characters in parameter substitutions.
Fixes koalaman/shellcheck#562. Special characters inside braces are parsed into T_ParamSubSpecialChar instead of T_Literal so that they are not flagged in the function checkInexplicablyUnquoted when sandwiched between double quotes.
This commit is contained in:
parent
9703f89f79
commit
0897ab7092
3 changed files with 13 additions and 2 deletions
|
@ -64,6 +64,7 @@ variableStart = upper <|> lower <|> oneOf "_"
|
|||
variableChars = upper <|> lower <|> digit <|> oneOf "_"
|
||||
functionChars = variableChars <|> oneOf ":+-.?"
|
||||
specialVariable = oneOf "@*#?-$!"
|
||||
paramSubSpecialChars = oneOf "/:+-=%"
|
||||
quotableChars = "|&;<>()\\ '\t\n\r\xA0" ++ doubleQuotableChars
|
||||
quotable = almostSpace <|> unicodeDoubleQuote <|> oneOf quotableChars
|
||||
bracedQuotable = oneOf "}\"$`'"
|
||||
|
@ -1003,13 +1004,20 @@ readDollarBracedWord = do
|
|||
list <- many readDollarBracedPart
|
||||
return $ T_NormalWord id list
|
||||
|
||||
readDollarBracedPart = readSingleQuoted <|> readDoubleQuoted <|> readExtglob <|> readNormalDollar <|> readUnquotedBackTicked <|> readDollarBracedLiteral
|
||||
readDollarBracedPart = readSingleQuoted <|> readDoubleQuoted <|>
|
||||
readParamSubSpecialChar <|> readExtglob <|> readNormalDollar <|>
|
||||
readUnquotedBackTicked <|> readDollarBracedLiteral
|
||||
|
||||
readDollarBracedLiteral = do
|
||||
id <- getNextId
|
||||
vars <- (readBraceEscaped <|> (anyChar >>= \x -> return [x])) `reluctantlyTill1` bracedQuotable
|
||||
return $ T_Literal id $ concat vars
|
||||
|
||||
readParamSubSpecialChar = do
|
||||
id <- getNextId
|
||||
many1 paramSubSpecialChars
|
||||
return $ T_ParamSubSpecialChar id
|
||||
|
||||
prop_readProcSub1 = isOk readProcSub "<(echo test | wc -l)"
|
||||
prop_readProcSub2 = isOk readProcSub "<( if true; then true; fi )"
|
||||
prop_readProcSub3 = isOk readProcSub "<( # nothing here \n)"
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue