mirror of
https://github.com/koalaman/shellcheck
synced 2025-07-15 09:33:09 -07:00
Fix parsing of [$var] (fixes #2309)
This commit is contained in:
parent
ecacc2e9bb
commit
081f7eba24
5 changed files with 54 additions and 19 deletions
|
@ -1372,6 +1372,8 @@ prop_readGlob5 = isOk readGlob "[^[:alpha:]1-9]"
|
|||
prop_readGlob6 = isOk readGlob "[\\|]"
|
||||
prop_readGlob7 = isOk readGlob "[^[]"
|
||||
prop_readGlob8 = isOk readGlob "[*?]"
|
||||
prop_readGlob9 = isOk readGlob "[!]^]"
|
||||
prop_readGlob10 = isOk readGlob "[]]"
|
||||
readGlob = readExtglob <|> readSimple <|> readClass <|> readGlobbyLiteral
|
||||
where
|
||||
readSimple = do
|
||||
|
@ -1379,22 +1381,25 @@ readGlob = readExtglob <|> readSimple <|> readClass <|> readGlobbyLiteral
|
|||
c <- oneOf "*?"
|
||||
id <- endSpan start
|
||||
return $ T_Glob id [c]
|
||||
-- Doesn't handle weird things like [^]a] and [$foo]. fixme?
|
||||
readClass = try $ do
|
||||
start <- startSpan
|
||||
char '['
|
||||
s <- many1 (predefined <|> readNormalLiteralPart "]" <|> globchars)
|
||||
negation <- charToString (oneOf "!^") <|> return ""
|
||||
leadingBracket <- charToString (oneOf "]") <|> return ""
|
||||
s <- many (predefined <|> readNormalLiteralPart "]" <|> globchars)
|
||||
guard $ not (null leadingBracket) || not (null s)
|
||||
char ']'
|
||||
id <- endSpan start
|
||||
return $ T_Glob id $ "[" ++ concat s ++ "]"
|
||||
return $ T_Glob id $ "[" ++ concat (negation:leadingBracket:s) ++ "]"
|
||||
where
|
||||
globchars = fmap return . oneOf $ "!$[" ++ extglobStartChars
|
||||
globchars = charToString $ oneOf $ "![" ++ extglobStartChars
|
||||
predefined = do
|
||||
try $ string "[:"
|
||||
s <- many1 letter
|
||||
string ":]"
|
||||
return $ "[:" ++ s ++ ":]"
|
||||
|
||||
charToString = fmap return
|
||||
readGlobbyLiteral = do
|
||||
start <- startSpan
|
||||
c <- extglobStart <|> char '['
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue