Skip to content

Commit 82cccaa

Browse files
Fixed empty variable parsing
1 parent 124efcd commit 82cccaa

File tree

3 files changed

+14
-15
lines changed

3 files changed

+14
-15
lines changed

src/Lines.php

Lines changed: 7 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public static function process(array $lines)
2222
foreach ($lines as $line) {
2323
list($multiline, $line, $multilineBuffer) = self::multilineProcess($multiline, $line, $multilineBuffer);
2424

25-
if (!$multiline && !self::isComment($line) && self::isSetter($line)) {
25+
if (!$multiline && !self::isCommentOrWhitespace($line)) {
2626
$output[] = $line;
2727
}
2828
}
@@ -115,28 +115,20 @@ private static function getCharPairs($line)
115115
}
116116

117117
/**
118-
* Determine if the line in the file is a comment, e.g. begins with a #.
118+
* Determine if the line in the file is a comment or whitespace.
119119
*
120120
* @param string $line
121121
*
122122
* @return bool
123123
*/
124-
private static function isComment($line)
124+
private static function isCommentOrWhitespace($line)
125125
{
126+
if (trim($line) === '') {
127+
return true;
128+
}
129+
126130
$line = ltrim($line);
127131

128132
return isset($line[0]) && $line[0] === '#';
129133
}
130-
131-
/**
132-
* Determine if the given line looks like it's setting a variable.
133-
*
134-
* @param string $line
135-
*
136-
* @return bool
137-
*/
138-
private static function isSetter($line)
139-
{
140-
return strpos($line, '=') !== false;
141-
}
142134
}

tests/Dotenv/DotenvTest.php

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -236,6 +236,12 @@ public function testMutlilineLoading()
236236
$this->assertSame('https://vision.googleapis.com/v1/images:annotate?key=', getenv('TEST_EQS'));
237237
}
238238

239+
public function testEmptyLoading()
240+
{
241+
$dotenv = Dotenv::create($this->fixturesFolder, 'empty.env');
242+
$this->assertSame(['EMPTY_VAR' => null], $dotenv->load());
243+
}
244+
239245
public function testGetEnvironmentVariablesList()
240246
{
241247
$dotenv = Dotenv::create($this->fixturesFolder);

tests/fixtures/env/empty.env

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
EMPTY_VAR

0 commit comments

Comments
 (0)