Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitde314bf

Browse files
committed
throw a meaningful exception when parsing dotenv files with BOM
1 parente104cd2 commitde314bf

File tree

3 files changed

+18
-1
lines changed

3 files changed

+18
-1
lines changed

‎src/Symfony/Component/Dotenv/Dotenv.php‎

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -568,7 +568,13 @@ private function doLoad(bool $overrideExistingVars, array $paths): void
568568
thrownewPathException($path);
569569
}
570570

571-
$this->populate($this->parse(file_get_contents($path),$path),$overrideExistingVars);
571+
$data =file_get_contents($path);
572+
573+
if ("\xEF\xBB\xBF" ===substr($data,0,3)) {
574+
thrownewFormatException('Loading files starting with a byte-order-mark is not supported.',newFormatExceptionContext($data,$path,1,0));
575+
}
576+
577+
$this->populate($this->parse($data,$path),$overrideExistingVars);
572578
}
573579
}
574580
}

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -604,4 +604,14 @@ public function testBootEnv()
604604
$resetContext();
605605
rmdir($tmpdir);
606606
}
607+
608+
publicfunctiontestExceptionWithBom()
609+
{
610+
$dotenv =newDotenv();
611+
612+
$this->expectException(FormatException::class);
613+
$this->expectExceptionMessage('Loading files starting with a byte-order-mark is not supported.');
614+
615+
$dotenv->load(__DIR__.'/fixtures/file_with_bom');
616+
}
607617
}
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
FOO=BAR

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp