Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
5 changes: 3 additions & 2 deletions src/Dotenv/Internal/Parser.purs
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ quotedValue q =
in
valueFromValues <$>
( char q
*> (some $ variableSubstitution <|> commandSubstitution <|> literal)
*> (many $ variableSubstitution <|> commandSubstitution <|> literal)
<* char q
)

Expand All @@ -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

Expand Down
9 changes: 8 additions & 1 deletion test/Parse.purs
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,11 @@ tests = describe "parser" do
]
actual = runParser "A=\"Hello, $(head -n 1 user.txt)!\"" parser
in
actual `shouldEqual` expected
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