fix: aliases: Make sure we can escape forward slashes in account
aliases, but otherwise the regular expression handler handles escapes.
This commit is contained in:
parent
cbdd86f4dc
commit
e6bf04fce3
@ -1517,15 +1517,17 @@ regexaliasp = do
|
|||||||
-- dbgparse 0 "regexaliasp"
|
-- dbgparse 0 "regexaliasp"
|
||||||
(off1, off2, re) <- between (char '/') (char '/') $ do
|
(off1, off2, re) <- between (char '/') (char '/') $ do
|
||||||
off1 <- getOffset
|
off1 <- getOffset
|
||||||
re <- some $ noneOf ("/\\\n\r" :: [Char]) -- paranoid: don't try to read past line end
|
re <- fmap T.concat . some $
|
||||||
<|> (char '\\' *> anySingle) -- allow escaping any character
|
(T.singleton <$> noneOf ("/\\\n\r" :: [Char])) -- paranoid: don't try to read past line end
|
||||||
|
<|> string "\\/" -- allow escaping forward slashes
|
||||||
|
<|> (liftM2 T.cons (char '\\') (T.singleton <$> anySingle)) -- Otherwise leave backslashes in
|
||||||
off2 <- getOffset
|
off2 <- getOffset
|
||||||
return (off1, off2, re)
|
return (off1, off2, re)
|
||||||
skipNonNewlineSpaces
|
skipNonNewlineSpaces
|
||||||
char '='
|
char '='
|
||||||
skipNonNewlineSpaces
|
skipNonNewlineSpaces
|
||||||
repl <- anySingle `manyTill` eolof
|
repl <- anySingle `manyTill` eolof
|
||||||
case toRegexCI $ T.pack re of
|
case toRegexCI re of
|
||||||
Right r -> return $! RegexAlias r repl
|
Right r -> return $! RegexAlias r repl
|
||||||
Left e -> customFailure $! parseErrorAtRegion off1 off2 e
|
Left e -> customFailure $! parseErrorAtRegion off1 off2 e
|
||||||
|
|
||||||
|
|||||||
@ -267,3 +267,33 @@ $ hledger -f- print
|
|||||||
b
|
b
|
||||||
|
|
||||||
>=0
|
>=0
|
||||||
|
|
||||||
|
# 19. Make sure you can escape special regexp characters.
|
||||||
|
<
|
||||||
|
alias /\./ = :
|
||||||
|
|
||||||
|
2021-01-01
|
||||||
|
hi.there 1
|
||||||
|
b
|
||||||
|
|
||||||
|
$ hledger -f- print
|
||||||
|
2021-01-01
|
||||||
|
hi:there 1
|
||||||
|
b
|
||||||
|
|
||||||
|
>=0
|
||||||
|
|
||||||
|
# 20. Including backslashes
|
||||||
|
<
|
||||||
|
alias /\\/ = :
|
||||||
|
|
||||||
|
2021-01-01
|
||||||
|
hi\there 1
|
||||||
|
b
|
||||||
|
|
||||||
|
$ hledger -f- print
|
||||||
|
2021-01-01
|
||||||
|
hi:there 1
|
||||||
|
b
|
||||||
|
|
||||||
|
>=0
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user