Skip to content

Commit a5de551

Browse files
authored
Merge pull request #6625 from paulbalandan/dotenv-export
Fix DotEnv class turning `export` to empty string
2 parents 9b810b8 + eabdcbd commit a5de551

3 files changed

Lines changed: 29 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: 21 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -55,14 +55,30 @@ 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+
['banana', 'fruit.export'],
81+
];
6682
}
6783

6884
/**

tests/system/Config/fixtures/.env

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,12 @@ 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+
fruit.export = "banana"
12+
713
SimpleConfig.onedeep=baz
814
SimpleConfig.default.name=ci4
915
# Use underscore as separator

0 commit comments

Comments
 (0)