Skip to content

Commit

Permalink
test: Add tests for correctly escaping new lines characters \n
Browse files Browse the repository at this point in the history
  • Loading branch information
FranzGB committed Jun 11, 2024
1 parent adb6062 commit a8b8d4f
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
5 changes: 5 additions & 0 deletions spec/fixtures/.dotenv
Original file line number Diff line number Diff line change
Expand Up @@ -4,3 +4,8 @@ ENVIRONMENT="$HOME"
PREVIOUS="$DOTENV"
ME="$(whoami)"
BLANK=
NEWLINE_TEST="Hello\nWorld"
MULTILINE_TEST="Roses are red
Violets are blue
Code is my art
And bugs are my glue"
5 changes: 3 additions & 2 deletions src/Configuration/Dotenv/Parse.hs
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ import Text.Megaparsec (Parsec, anySingle,
between, eof, noneOf,
oneOf, sepEndBy, (<?>))
import Text.Megaparsec.Char (char, digitChar, eol,
letterChar, spaceChar)
letterChar, spaceChar, string)
import qualified Text.Megaparsec.Char.Lexer as L

type Parser = Parsec Void String
Expand Down Expand Up @@ -85,8 +85,9 @@ interpolatedValueCommandInterpolation = do
symbol = L.symbol sc

literalValueFragment :: String -> Parser VarFragment
literalValueFragment charsToEscape = VarLiteral <$> some (escapedChar <|> normalChar)
literalValueFragment charsToEscape = VarLiteral <$> some (newlineChar <|> escapedChar <|> normalChar)
where
newlineChar = string "\\n" >> return '\n'
escapedChar = (char '\\' *> anySingle) <?> "escaped character"
normalChar = noneOf charsToEscape <?> "unescaped character"

Expand Down

0 comments on commit a8b8d4f

Please sign in to comment.