diff --git a/CHANGELOG.md b/CHANGELOG.md index 34538d5..61830c8 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -10,6 +10,8 @@ New features: Bugfixes: +- Empty values (`A=`, `A=""`, `A=''`) are now parsed as the empty string instead of failing to parse. + Other improvements: ## [4.0.3] - 2023-08-05 diff --git a/src/Dotenv/Internal/Parser.purs b/src/Dotenv/Internal/Parser.purs index 147f8c9..f87f631 100644 --- a/src/Dotenv/Internal/Parser.purs +++ b/src/Dotenv/Internal/Parser.purs @@ -76,7 +76,7 @@ quotedValue q = in valueFromValues <$> ( char q - *> (some $ variableSubstitution <|> commandSubstitution <|> literal) + *> (many $ variableSubstitution <|> commandSubstitution <|> literal) <* char q ) @@ -97,12 +97,13 @@ unquotedValue = in valueFromValues <$> ( whiteSpace *> - (some $ variableSubstitution <|> commandSubstitution <|> literal) + (many $ variableSubstitution <|> commandSubstitution <|> literal) ) -- | Assembles a single value from a series of values. valueFromValues :: Array UnresolvedValue -> UnresolvedValue valueFromValues v + | length v == 0 = LiteralValue "" | length v == 1 = fromMaybe (ValueExpression []) (head v) | otherwise = ValueExpression v diff --git a/test/Parse.purs b/test/Parse.purs index 555261c..ec464b5 100644 --- a/test/Parse.purs +++ b/test/Parse.purs @@ -159,4 +159,11 @@ tests = describe "parser" do ] actual = runParser "A=\"Hello, $(head -n 1 user.txt)!\"" parser in - actual `shouldEqual` expected \ No newline at end of file + actual `shouldEqual` expected + + it "parses an empty value as the empty string" $ + let + expected = Right [ "A" /\ LiteralValue "" ] + actual = runParser "A=" parser + in + actual `shouldEqual` expected