Skip to content

Commit b9ea8f7

Browse files
committed
Fix DotEnv class turning export to empty string
1 parent a7fb29f commit b9ea8f7

3 files changed

Lines changed: 27 additions & 6 deletions

File tree

‎system/Config/DotEnv.php‎

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,7 +116,8 @@ public function normaliseVariable(string $name, string $value = ''): array
116116
$value = trim($value);
117117

118118
// Sanitize the name
119-
$name = str_replace(['export', '\'', '"'], '', $name);
119+
$name = preg_replace('/^export[ \t]++(\S+)/', '$1', $name);
120+
$name = str_replace(['\'', '"'], '', $name);
120121

121122
// Sanitize the value
122123
$value = $this->sanitizeValue($value);

‎tests/system/Config/DotEnvTest.php‎

Lines changed: 20 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,29 @@ public function testReturnsFalseIfCannotFindFile()
5555
$this->assertFalse($dotenv->load());
5656
}
5757

58-
public function testLoadsVars()
58+
/**
59+
* @dataProvider provideLoadVars
60+
*/
61+
public function testLoadsVars(string $expected, string $varname)
5962
{
6063
$dotenv = new DotEnv($this->fixturesFolder);
6164
$dotenv->load();
62-
$this->assertSame('bar', getenv('FOO'));
63-
$this->assertSame('baz', getenv('BAR'));
64-
$this->assertSame('with spaces', getenv('SPACED'));
65-
$this->assertSame('', getenv('NULL'));
65+
66+
$this->assertSame($expected, getenv($varname));
67+
}
68+
69+
public function provideLoadVars(): iterable
70+
{
71+
yield from [
72+
['bar', 'FOO'],
73+
['baz', 'BAR'],
74+
['with spaces', 'SPACED'],
75+
['', 'NULL'],
76+
['exported foo', 'char.expo.foo'],
77+
['variable', 'character.export.var'],
78+
['character', 'char.var'],
79+
['imports', 'char.exports'],
80+
];
6681
}
6782

6883
/**

‎tests/system/Config/fixtures/.env‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,11 @@ SPACED="with spaces"
44

55
NULL=
66

7+
char.expo.foo="exported foo"
8+
character.export.var=variable
9+
export char.var=character
10+
export char.exports=imports
11+
712
SimpleConfig.onedeep=baz
813
SimpleConfig.default.name=ci4
914
# Use underscore as separator

0 commit comments

Comments
 (0)