File tree Expand file tree Collapse file tree 3 files changed +13
-7
lines changed
Expand file tree Collapse file tree 3 files changed +13
-7
lines changed Original file line number Diff line number Diff line change @@ -253,14 +253,14 @@ protected function sanitiseVariableValue($name, $value)
253253 $ parts = explode (' # ' , $ value , 2 );
254254 $ value = trim ($ parts [0 ]);
255255
256- // Check if value is a comment (usually triggered when empty value with comment)
257- if (preg_match ('/^#/ ' , $ value ) > 0 ) {
258- $ value = '' ;
259- }
260-
261256 // Unquoted values cannot contain whitespace
262257 if (preg_match ('/\s+/ ' , $ value ) > 0 ) {
263- throw new InvalidFileException ('Dotenv values containing spaces must be surrounded by quotes. ' );
258+ // Check if value is a comment (usually triggered when empty value with comment)
259+ if (preg_match ('/^#/ ' , $ value ) > 0 ) {
260+ $ value = '' ;
261+ } else {
262+ throw new InvalidFileException ('Dotenv values containing spaces must be surrounded by quotes. ' );
263+ }
264264 }
265265 }
266266
Original file line number Diff line number Diff line change @@ -52,6 +52,7 @@ public function testCommentedDotenvLoadsEnvironmentVars()
5252 $ this ->assertSame ('a value with a # character ' , getenv ('CQUOTES ' ));
5353 $ this ->assertSame ('a value with a # character & a quote " character inside quotes ' , getenv ('CQUOTESWITHQUOTE ' ));
5454 $ this ->assertEmpty (getenv ('CNULL ' ));
55+ $ this ->assertEmpty (getenv ('EMPTY ' ));
5556 }
5657
5758 public function testQuotedDotenvLoadsEnvironmentVars ()
@@ -261,23 +262,27 @@ public function testDotenvAssertions()
261262 $ this ->assertEmpty (getenv ('ASSERTVAR2 ' ));
262263 $ this ->assertEmpty (getenv ('ASSERTVAR3 ' ));
263264 $ this ->assertSame ('0 ' , getenv ('ASSERTVAR4 ' ));
265+ $ this ->assertSame ('#foo ' , getenv ('ASSERTVAR5 ' ));
264266
265267 $ dotenv ->required (array (
266268 'ASSERTVAR1 ' ,
267269 'ASSERTVAR2 ' ,
268270 'ASSERTVAR3 ' ,
269271 'ASSERTVAR4 ' ,
272+ 'ASSERTVAR5 ' ,
270273 ));
271274
272275 $ dotenv ->required (array (
273276 'ASSERTVAR1 ' ,
274277 'ASSERTVAR4 ' ,
278+ 'ASSERTVAR5 ' ,
275279 ))->notEmpty ();
276280
277281 $ dotenv ->required (array (
278282 'ASSERTVAR1 ' ,
279283 'ASSERTVAR4 ' ,
280- ))->notEmpty ()->allowedValues (array ('0 ' , 'val1 ' ));
284+ 'ASSERTVAR5 ' ,
285+ ))->notEmpty ()->allowedValues (array ('0 ' , 'val1 ' , '#foo ' ));
281286
282287 $ this ->assertTrue (true ); // anything wrong an an exception will be thrown
283288 }
Original file line number Diff line number Diff line change @@ -2,3 +2,4 @@ ASSERTVAR1="val1"
22ASSERTVAR2 = " "
33ASSERTVAR3 = " "
44ASSERTVAR4 = " 0" # empty looking value
5+ ASSERTVAR5 = #foo
You can’t perform that action at this time.
0 commit comments