File size: 2,249 Bytes
5fcd275 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 | diff --git a/src/Knp/Snappy/AbstractGenerator.php b/src/Knp/Snappy/AbstractGenerator.php
index 643376f2..1189e95a 100644
--- a/src/Knp/Snappy/AbstractGenerator.php
+++ b/src/Knp/Snappy/AbstractGenerator.php
@@ -625,8 +625,13 @@ protected function executeCommand($command)
*/
protected function prepareOutput($filename, $overwrite)
{
- if (\strpos($filename, 'phar://') === 0) {
- throw new InvalidArgumentException('The output file cannot be a phar archive.');
+ if (false === $parsedFilename = \parse_url($filename)) {
+ throw new InvalidArgumentException('The output filename is invalid.');
+ }
+
+ $scheme = isset($parsedFilename['scheme']) ? \mb_strtolower($parsedFilename['scheme']) : '';
+ if ($scheme !== '' && $scheme !== 'file') {
+ throw new InvalidArgumentException(\sprintf('The output file scheme is not supported. Expected \'\' or \'file\' but got \'%s\'.', $scheme));
}
$directory = \dirname($filename);
diff --git a/tests/Knp/Snappy/AbstractGeneratorTest.php b/tests/Knp/Snappy/AbstractGeneratorTest.php
index 1ab6a900..da5136a8 100644
--- a/tests/Knp/Snappy/AbstractGeneratorTest.php
+++ b/tests/Knp/Snappy/AbstractGeneratorTest.php
@@ -965,6 +965,30 @@ public function testFailingGenerateWithOutputContainingPharPrefix(): void
$media->generate('the_input_file', 'phar://the_output_file', ['foo' => 'bar']);
}
+ public function testFailingGenerateWithOutputContainingUppercasePharPrefix(): void
+ {
+ $media = $this->getMockBuilder(AbstractGenerator::class)
+ ->setMethods([
+ 'configure',
+ 'prepareOutput',
+ ])
+ ->setConstructorArgs(['the_binary', [], ['PATH' => '/usr/bin']])
+ ->getMock()
+ ;
+
+ $media->setTimeout(2000);
+
+ $media
+ ->expects($this->once())
+ ->method('prepareOutput')
+ ->with($this->equalTo('PHAR://the_output_file'))
+ ;
+
+ $this->expectException(InvalidArgumentException::class);
+
+ $media->generate('the_input_file', 'PHAR://the_output_file', ['foo' => 'bar']);
+ }
+
/**
* @return null|string
*/
|