Skip to content

Commit 39b023d

Browse files
committed
Add support for empty unquoted values
1 parent 8ddf221 commit 39b023d

File tree

3 files changed

+23
-5
lines changed

3 files changed

+23
-5
lines changed

ROADMAP.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -105,12 +105,20 @@ Envious.parse("KEY=value\nINVALID")
105105
## Medium Priority
106106

107107
### 6. Support for Empty Values
108-
**Status:** Pending
109-
**File:** `lib/envious/parser.ex`
108+
**Status:** ✅ Complete
109+
**File:** `lib/envious/parser.ex:154-157`
110110

111111
Allow variables to be set to empty strings: `KEY=`
112112

113-
**Note:** This overlaps with item #1 but deserves explicit testing and handling.
113+
**Completed:** Updated unquoted value parser to accept 0 or more characters (changed `min: 1` to `min: 0`). Empty values now parse to empty strings, consistent with quoted empty values.
114+
115+
**Changes made:**
116+
- Changed `unquoted_value` parser to allow `min: 0` characters
117+
- Added 2 test cases for empty unquoted values
118+
- All three empty value syntaxes now work:
119+
- `KEY=""``%{"KEY" => ""}`
120+
- `KEY=''``%{"KEY" => ""}`
121+
- `KEY=``%{"KEY" => ""}`
114122

115123
### 7. Variable Expansion
116124
**Status:** Pending

lib/envious/parser.ex

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -148,11 +148,11 @@ defmodule Envious.Parser do
148148
])
149149

150150
# Unquoted value: traditional unquoted values
151-
# - Collect 1 or more value characters
151+
# - Collect 0 or more value characters (allows empty values like KEY=)
152152
# - Convert the character list to a string
153153
# - Trim whitespace from both ends (handles inline comments: "value # comment")
154154
unquoted_value =
155-
times(unquoted_value_char, min: 1)
155+
times(unquoted_value_char, min: 0)
156156
|> reduce({List, :to_string, []})
157157
|> post_traverse(:trim_value)
158158

test/envious_test.exs

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,16 @@ defmodule EnviousTest do
9090
{:ok, %{"EMPTY" => ""}}
9191
end
9292

93+
test "empty unquoted value" do
94+
assert Envious.parse("EMPTY=") ==
95+
{:ok, %{"EMPTY" => ""}}
96+
end
97+
98+
test "empty unquoted value with newline" do
99+
assert Envious.parse("EMPTY=\nKEY=value") ==
100+
{:ok, %{"EMPTY" => "", "KEY" => "value"}}
101+
end
102+
93103
# Error handling tests
94104
test "unclosed double quote returns error" do
95105
assert {:error, message} = Envious.parse("KEY=\"unclosed")

0 commit comments

Comments
 (0)