Skip to content

Commit eccbcce

Browse files
authored
Merge pull request #4276 from oleibman/streamcontext
Additional Context Options for https, Restore Disabled Tests
2 parents 1e78397 + 92292e5 commit eccbcce

File tree

5 files changed

+24
-9
lines changed

5 files changed

+24
-9
lines changed

CHANGELOG.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@ and this project adheres to [Semantic Versioning](https://semver.org).
2121

2222
### Deprecated
2323

24-
- Nothing yet.
24+
- Drawing::setIsUrl is unneeded. The property is set when setPath determines whether path is a url.
2525

2626
### Fixed
2727

28-
- Nothing yet.
28+
- More context options may be needed for http(s) image. [Php issue 17121](https://github.com/php/php-src/issues/17121) [PR #4276](https://github.com/PHPOffice/PhpSpreadsheet/pull/4276)
2929

3030
## 2024-12-08 - 3.6.0
3131

src/PhpSpreadsheet/Worksheet/Drawing.php

+17-2
Original file line numberDiff line numberDiff line change
@@ -111,8 +111,21 @@ public function setPath(string $path, bool $verifyFile = true, ?ZipArchive $zip
111111
$this->isUrl = true;
112112
$ctx = null;
113113
// 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]]);
114+
// https://github.com/php/php-src/issues/17121
115+
if (str_starts_with($path, 'https:') || str_starts_with($path, 'http:')) {
116+
$ctxArray = [
117+
'http' => [
118+
'user_agent' => 'Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/131.0.0.0 Safari/537.36',
119+
'header' => [
120+
//'Connection: keep-alive', // unacceptable performance
121+
'Accept: image/*;q=0.9,*/*;q=0.8',
122+
],
123+
],
124+
];
125+
if (str_starts_with($path, 'https:')) {
126+
$ctxArray['ssl'] = ['crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT];
127+
}
128+
$ctx = stream_context_create($ctxArray);
116129
}
117130
$imageContents = @file_get_contents($path, false, $ctx);
118131
if ($imageContents !== false) {
@@ -183,6 +196,8 @@ public function getIsURL(): bool
183196
* Set isURL.
184197
*
185198
* @return $this
199+
*
200+
* @deprecated 3.7.0 not needed, property is set by setPath
186201
*/
187202
public function setIsURL(bool $isUrl): self
188203
{

tests/PhpSpreadsheetTests/Calculation/Functions/Logical/XorTest.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ public static function providerXOR(): array
1818
}
1919

2020
#[\PHPUnit\Framework\Attributes\DataProvider('providerXORLiteral')]
21-
public function xtestXORLiteral(mixed $expectedResult, string $formula): void
21+
public function testXORLiteral(mixed $expectedResult, float|string $formula): void
2222
{
2323
$sheet = $this->getSheet();
2424
$sheet->getCell('A1')->setValue("=XOR($formula)");

tests/PhpSpreadsheetTests/Reader/Html/HtmlImage2Test.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010

1111
class HtmlImage2Test extends TestCase
1212
{
13-
public function xtestCanInsertImageGoodProtocol(): void
13+
public function testCanInsertImageGoodProtocol(): void
1414
{
1515
if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
1616
self::markTestSkipped('Skipped due to setting of environment variable');
@@ -31,7 +31,7 @@ public function xtestCanInsertImageGoodProtocol(): void
3131
self::assertEquals('A1', $drawing->getCoordinates());
3232
}
3333

34-
public function xtestCantInsertImageNotFound(): void
34+
public function testCantInsertImageNotFound(): void
3535
{
3636
if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
3737
self::markTestSkipped('Skipped due to setting of environment variable');

tests/PhpSpreadsheetTests/Reader/Xlsx/URLImageTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212

1313
class URLImageTest extends TestCase
1414
{
15-
public function xtestURLImageSource(): void
15+
public function testURLImageSource(): void
1616
{
1717
if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
1818
self::markTestSkipped('Skipped due to setting of environment variable');
@@ -37,7 +37,7 @@ public function xtestURLImageSource(): void
3737
$spreadsheet->disconnectWorksheets();
3838
}
3939

40-
public function xtestURLImageSourceNotFound(): void
40+
public function testURLImageSourceNotFound(): void
4141
{
4242
if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
4343
self::markTestSkipped('Skipped due to setting of environment variable');

0 commit comments

Comments
 (0)