8000 minor #29797 [Dotenv] improved code coverage and removed unreachable … · symfony/symfony@f950364 · GitHub
[go: up one dir, main page]

Skip to content

Commit f950364

Browse files
committed
minor #29797 [Dotenv] improved code coverage and removed unreachable code (Stas-Soroka)
This PR was squashed before being merged into the 4.3-dev branch (closes #29797). Discussion ---------- [Dotenv] improved code coverage and removed unreachable code | Q | A | ------------- | --- | Branch? | master | Bug fix? | no | New feature? | no | BC breaks? | no | Deprecations? | no | Tests pass? | yes | License | MIT Commits ------- 34dac7c [Dotenv] improved code coverage and removed unreachable code
2 parents 9e9506e + 34dac7c commit f950364

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

src/Symfony/Component/Dotenv/Dotenv.php

Lines changed: 0 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -271,9 +271,6 @@ private function lexValue()
271271
throw $this->createFormatException('Missing quote to end the value');
272272
}
273273
}
274-
if ("\n" === $this->data[$this->cursor]) {
275-
throw $this->createFormatException('Missing quote to end the value');
276-
}
277274
++$this->cursor;
278275
$value = str_replace(array('\\"', '\r', '\n'), array('"', "\r", "\n"), $value);
279276
$resolvedValue = $value;

src/Symfony/Component/Dotenv/Tests/DotenvTest.php

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,14 @@ public function getEnvDataWithFormatErrors()
4040
array('FOO', "Missing = in the environment variable declaration in \".env\" at line 1.\n...FOO...\n ^ line 1 offset 3"),
4141
array('FOO="foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO=\"foo...\n ^ line 1 offset 8"),
4242
array('FOO=\'foo', "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo...\n ^ line 1 offset 8"),
43+
array('FOO=\'foo'."\n", "Missing quote to end the value in \".env\" at line 1.\n...FOO='foo\\n...\n ^ line 1 offset 8"),
4344
array('export FOO', "Unable to unset an environment variable in \".env\" at line 1.\n...export FOO...\n ^ line 1 offset 10"),
4445
array('FOO=${FOO', "Unclosed braces on variable expansion in \".env\" at line 1.\n...FOO=\${FOO...\n ^ line 1 offset 9"),
46+
array('FOO= BAR', "Whitespace are not supported before the value in \".env\" at line 1.\n...FOO= BAR...\n ^ line 1 offset 4"),
47+
array('Стасян', "Invalid character in variable name in \".env\" at line 1.\n...Стасян...\n ^ line 1 offset 0"),
48+
array('FOO!', "Missing = in the environment variable declaration in \".env\" at line 1.\n...FOO!...\n ^ line 1 offset 3"),
49+
array('FOO=$(echo foo', "Missing closing parenthesis. in \".env\" at line 1.\n...FOO=$(echo foo...\n ^ line 1 offset 14"),
50+
array('FOO=$(echo foo'."\n", "Missing closing parenthesis. in \".env\" at line 1.\n...FOO=$(echo foo\\n...\n ^ line 1 offset 14"),
4551
);
4652

4753
if ('\\' !== \DIRECTORY_SEPARATOR) {
@@ -64,6 +70,7 @@ public function getEnvData()
6470
{
6571
putenv('LOCAL=local');
6672
$_ENV['REMOTE'] = 'remote';
73+
$_SERVER['SERVERVAR'] = 'servervar';
6774

6875
$tests = array(
6976
// backslashes
@@ -150,6 +157,7 @@ public function getEnvData()
150157
array('FOO=" $ "', array('FOO' => ' $ ')),
151158
array('BAR=$LOCAL', array('BAR' => 'local')),
152159
array('BAR=$REMOTE', array('BAR' => 'remote')),
160+
array('BAR=$SERVERVAR', array('BAR' => 'servervar')),
153161
array('FOO=$NOTDEFINED', array('FOO' => '')),
154162
);
155163

@@ -222,6 +230,7 @@ public function testLoadEnv()
222230

223231
// .env.local
224232

233+
$_SERVER['TEST_APP_ENV'] = 'local';
225234
file_put_contents("$path.local", 'FOO=localBAR');
226235
(new DotEnv())->loadEnv($path, 'TEST_APP_ENV');
227236
$this->assertSame('localBAR', getenv('FOO'));

0 commit comments

Comments
 (0)
0