@@ -24,9 +24,12 @@ VAR=VAR_VALUE
2424EMPTY_VAR=
2525UNDEFINED_VAR
2626DEFINED_VAR
27+ QUOTED_VAR
28+ QUOTED_VALUE="this should be quoted"
2729`
2830 vars := map [string ]string {
2931 "DEFINED_VAR" : "defined-value" ,
32+ "QUOTED_VAR" : "\" quoted value\" " ,
3033 }
3134 lookupFn := func (name string ) (string , bool ) {
3235 v , ok := vars [name ]
@@ -40,7 +43,13 @@ DEFINED_VAR
4043 variables , err := Parse (fileName , lookupFn )
4144 assert .NilError (t , err )
4245
43- expectedLines := []string {"VAR=VAR_VALUE" , "EMPTY_VAR=" , "DEFINED_VAR=defined-value" }
46+ expectedLines := []string {
47+ "VAR=VAR_VALUE" ,
48+ "EMPTY_VAR=" ,
49+ "DEFINED_VAR=defined-value" ,
50+ "QUOTED_VAR=quoted value" ,
51+ "QUOTED_VALUE=this should be quoted" ,
52+ }
4453 assert .Check (t , is .DeepEqual (variables , expectedLines ))
4554}
4655
@@ -118,9 +127,11 @@ VAR=VAR_VALUE
118127EMPTY_VAR=
119128UNDEFINED_VAR
120129DEFINED_VAR
130+ QUOTED_VAR
121131`
122132 vars := map [string ]string {
123133 "DEFINED_VAR" : "defined-value" ,
134+ "QUOTED_VAR" : "\" quoted value\" " ,
124135 }
125136 lookupFn := func (name string ) (string , bool ) {
126137 v , ok := vars [name ]
@@ -130,7 +141,12 @@ DEFINED_VAR
130141 variables , err := ParseFromReader (strings .NewReader (content ), lookupFn )
131142 assert .NilError (t , err )
132143
133- expectedLines := []string {"VAR=VAR_VALUE" , "EMPTY_VAR=" , "DEFINED_VAR=defined-value" }
144+ expectedLines := []string {
145+ "VAR=VAR_VALUE" ,
146+ "EMPTY_VAR=" ,
147+ "DEFINED_VAR=defined-value" ,
148+ "QUOTED_VAR=quoted value" ,
149+ }
134150 assert .Check (t , is .DeepEqual (variables , expectedLines ))
135151}
136152
@@ -143,3 +159,29 @@ func TestParseFromReaderWithNoName(t *testing.T) {
143159 const expectedMessage = "no variable name on line '=blank variable names are an error case'"
144160 assert .Check (t , is .ErrorContains (err , expectedMessage ))
145161}
162+
163+ // Test ParseFromReader with quoted values
164+ func TestParseFromReaderWithQuotes (t * testing.T ) {
165+ content := `# Test with quotes
166+ DOUBLE_QUOTES="double quoted value"
167+ SINGLE_QUOTES='single quoted value'
168+ MIXED_QUOTES="'mixed' quotes"
169+ NESTED_QUOTES='"nested" quotes'
170+ UNBALANCED_QUOTES="unbalanced quotes
171+ UNBALANCED_QUOTES2=unbalanced quotes"
172+ QUOTES_IN_MIDDLE=value "with" quotes
173+ `
174+ variables , err := ParseFromReader (strings .NewReader (content ), nil )
175+ assert .NilError (t , err )
176+
177+ expectedLines := []string {
178+ "DOUBLE_QUOTES=double quoted value" ,
179+ "SINGLE_QUOTES=single quoted value" ,
180+ "MIXED_QUOTES='mixed' quotes" ,
181+ "NESTED_QUOTES=\" nested\" quotes" ,
182+ "UNBALANCED_QUOTES=\" unbalanced quotes" ,
183+ "UNBALANCED_QUOTES2=unbalanced quotes\" " ,
184+ "QUOTES_IN_MIDDLE=value \" with\" quotes" ,
185+ }
186+ assert .Check (t , is .DeepEqual (variables , expectedLines ))
187+ }
0 commit comments