Fix parsing of escaped chars in regex groups. Fixes #1077

This commit is contained in:
Vidar Holen 2018-01-21 16:13:16 -08:00
parent c86885427c
commit ba5f20deda
1 changed files with 14 additions and 10 deletions

View File

@ -576,17 +576,19 @@ readConditionContents single =
<|> return False <|> return False
readRegex = called "regex" $ do readRegex = called "regex" $ do
id <- getNextId id <- getNextId
parts <- many1 ( parts <- many1 readPart
readGroup <|>
readSingleQuoted <|>
readDoubleQuoted <|>
readDollarExpression <|>
readNormalLiteral "( " <|>
readPipeLiteral <|>
readGlobLiteral)
void spacing void spacing
return $ T_NormalWord id parts return $ T_NormalWord id parts
where where
readPart = choice [
readGroup,
readSingleQuoted,
readDoubleQuoted,
readDollarExpression,
readNormalLiteral "( ",
readPipeLiteral,
readGlobLiteral
]
readGlobLiteral = do readGlobLiteral = do
id <- getNextId id <- getNextId
s <- extglobStart <|> oneOf "{}[]$" s <- extglobStart <|> oneOf "{}[]$"
@ -594,7 +596,7 @@ readConditionContents single =
readGroup = called "regex grouping" $ do readGroup = called "regex grouping" $ do
id <- getNextId id <- getNextId
char '(' char '('
parts <- many (readGroup <|> readSingleQuoted <|> readDoubleQuoted <|> readDollarExpression <|> readRegexLiteral <|> readGlobLiteral) parts <- many (readPart <|> readRegexLiteral)
char ')' char ')'
return $ T_NormalWord id parts return $ T_NormalWord id parts
readRegexLiteral = do readRegexLiteral = do
@ -836,6 +838,8 @@ prop_readCondition17= isOk readCondition "[[ ${file::1} = [-.\\|/\\\\] ]]"
prop_readCondition18= isOk readCondition "[ ]" prop_readCondition18= isOk readCondition "[ ]"
prop_readCondition19= isOk readCondition "[ '(' x \")\" ]" prop_readCondition19= isOk readCondition "[ '(' x \")\" ]"
prop_readCondition20= isOk readCondition "[[ echo_rc -eq 0 ]]" prop_readCondition20= isOk readCondition "[[ echo_rc -eq 0 ]]"
prop_readCondition21= isOk readCondition "[[ $1 =~ ^(a\\ b)$ ]]"
prop_readCondition22= isOk readCondition "[[ $1 =~ \\.a\\.(\\.b\\.)\\.c\\. ]]"
readCondition = called "test expression" $ do readCondition = called "test expression" $ do
opos <- getPosition opos <- getPosition
id <- getNextId id <- getNextId
@ -2679,7 +2683,7 @@ readShebang = do
parseProblemAt pos ErrorC 1084 parseProblemAt pos ErrorC 1084
"Use #!, not !#, for the shebang." "Use #!, not !#, for the shebang."
skipSpaces = liftM (not . null) $ many linewhitespace skipSpaces = fmap (not . null) $ many linewhitespace
readTooManySpaces = do readTooManySpaces = do
startPos <- getPosition startPos <- getPosition
startSpaces <- skipSpaces startSpaces <- skipSpaces