Skip to content

Commit 498afe2

Browse files
authored
Merge pull request #4170 from oleibman/urlreinstate
Restore 2 Disabled Tests
2 parents 9d7aaff + 512c21e commit 498afe2

File tree

3 files changed

+15
-16
lines changed

3 files changed

+15
-16
lines changed

src/PhpSpreadsheet/Reader/Xlsx.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1451,7 +1451,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
14511451
);
14521452
if (isset($images[$linkImageKey])) {
14531453
$url = str_replace('xl/drawings/', '', $images[$linkImageKey]);
1454-
$objDrawing->setPath($url);
1454+
$objDrawing->setPath($url, false);
14551455
}
14561456
if ($objDrawing->getPath() === '') {
14571457
continue;
@@ -1544,7 +1544,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
15441544
);
15451545
if (isset($images[$linkImageKey])) {
15461546
$url = str_replace('xl/drawings/', '', $images[$linkImageKey]);
1547-
$objDrawing->setPath($url);
1547+
$objDrawing->setPath($url, false);
15481548
}
15491549
if ($objDrawing->getPath() === '') {
15501550
continue;

src/PhpSpreadsheet/Worksheet/Drawing.php

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -109,7 +109,12 @@ public function setPath(string $path, bool $verifyFile = true, ?ZipArchive $zip
109109
}
110110
// Implicit that it is a URL, rather store info than running check above on value in other places.
111111
$this->isUrl = true;
112-
$imageContents = @file_get_contents($path);
112+
$ctx = null;
113+
// https://github.com/php/php-src/issues/16023
114+
if (str_starts_with($path, 'https:')) {
115+
$ctx = stream_context_create(['ssl' => ['crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT]]);
116+
}
117+
$imageContents = @file_get_contents($path, false, $ctx);
113118
if ($imageContents !== false) {
114119
$filePath = tempnam(sys_get_temp_dir(), 'Drawing');
115120
if ($filePath) {

tests/PhpSpreadsheetTests/Reader/Xlsx/URLImageTest.php

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,7 @@
1212

1313
class URLImageTest extends TestCase
1414
{
15-
// https://github.com/readthedocs/readthedocs.org/issues/11615
16-
public function xtestURLImageSource(): void
15+
public function testURLImageSource(): void
1716
{
1817
if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
1918
self::markTestSkipped('Skipped due to setting of environment variable');
@@ -31,20 +30,14 @@ public function xtestURLImageSource(): void
3130
// Check if the source is a URL or a file path
3231
self::assertTrue($drawing->getIsURL());
3332
self::assertSame('https://phpspreadsheet.readthedocs.io/en/latest/topics/images/01-03-filter-icon-1.png', $drawing->getPath());
34-
$imageContents = file_get_contents($drawing->getPath());
35-
self::assertNotFalse($imageContents);
36-
$filePath = tempnam(sys_get_temp_dir(), 'Drawing');
37-
self::assertNotFalse($filePath);
38-
self::assertNotFalse(file_put_contents($filePath, $imageContents));
39-
$mimeType = mime_content_type($filePath);
40-
unlink($filePath);
41-
self::assertNotFalse($mimeType);
42-
$extension = File::mime2ext($mimeType);
43-
self::assertSame('png', $extension);
33+
self::assertSame(IMAGETYPE_PNG, $drawing->getType());
34+
self::assertSame(84, $drawing->getWidth());
35+
self::assertSame(44, $drawing->getHeight());
4436
}
37+
$spreadsheet->disconnectWorksheets();
4538
}
4639

47-
public function xtestURLImageSourceNotFound(): void
40+
public function testURLImageSourceNotFound(): void
4841
{
4942
if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
5043
self::markTestSkipped('Skipped due to setting of environment variable');
@@ -56,6 +49,7 @@ public function xtestURLImageSourceNotFound(): void
5649
$worksheet = $spreadsheet->getActiveSheet();
5750
$collection = $worksheet->getDrawingCollection();
5851
self::assertCount(0, $collection);
52+
$spreadsheet->disconnectWorksheets();
5953
}
6054

6155
public function testURLImageSourceBadProtocol(): void

0 commit comments

Comments
 (0)