Skip to content

Additional Context Options for https, Restore Disabled Tests #4276

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 4 commits into from
Dec 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,11 @@ and this project adheres to [Semantic Versioning](https://semver.org).

### Deprecated

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

### Fixed

- Nothing yet.
- 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)

## 2024-12-08 - 3.6.0

Expand Down
19 changes: 17 additions & 2 deletions src/PhpSpreadsheet/Worksheet/Drawing.php
Original file line number Diff line number Diff line change
Expand Up @@ -111,8 +111,21 @@ public function setPath(string $path, bool $verifyFile = true, ?ZipArchive $zip
$this->isUrl = true;
$ctx = null;
// https://github.com/php/php-src/issues/16023
if (str_starts_with($path, 'https:')) {
$ctx = stream_context_create(['ssl' => ['crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT]]);
// https://github.com/php/php-src/issues/17121
if (str_starts_with($path, 'https:') || str_starts_with($path, 'http:')) {
$ctxArray = [
'http' => [
'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',
'header' => [
//'Connection: keep-alive', // unacceptable performance
'Accept: image/*;q=0.9,*/*;q=0.8',
],
],
];
if (str_starts_with($path, 'https:')) {
$ctxArray['ssl'] = ['crypto_method' => STREAM_CRYPTO_METHOD_TLSv1_3_CLIENT];
}
$ctx = stream_context_create($ctxArray);
}
$imageContents = @file_get_contents($path, false, $ctx);
if ($imageContents !== false) {
Expand Down Expand Up @@ -183,6 +196,8 @@ public function getIsURL(): bool
* Set isURL.
*
* @return $this
*
* @deprecated 3.7.0 not needed, property is set by setPath
*/
public function setIsURL(bool $isUrl): self
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ public static function providerXOR(): array
}

#[\PHPUnit\Framework\Attributes\DataProvider('providerXORLiteral')]
public function xtestXORLiteral(mixed $expectedResult, string $formula): void
public function testXORLiteral(mixed $expectedResult, float|string $formula): void
{
$sheet = $this->getSheet();
$sheet->getCell('A1')->setValue("=XOR($formula)");
Expand Down
4 changes: 2 additions & 2 deletions tests/PhpSpreadsheetTests/Reader/Html/HtmlImage2Test.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

class HtmlImage2Test extends TestCase
{
public function xtestCanInsertImageGoodProtocol(): void
public function testCanInsertImageGoodProtocol(): void
{
if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
self::markTestSkipped('Skipped due to setting of environment variable');
Expand All @@ -31,7 +31,7 @@ public function xtestCanInsertImageGoodProtocol(): void
self::assertEquals('A1', $drawing->getCoordinates());
}

public function xtestCantInsertImageNotFound(): void
public function testCantInsertImageNotFound(): void
{
if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
self::markTestSkipped('Skipped due to setting of environment variable');
Expand Down
4 changes: 2 additions & 2 deletions tests/PhpSpreadsheetTests/Reader/Xlsx/URLImageTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@

class URLImageTest extends TestCase
{
public function xtestURLImageSource(): void
public function testURLImageSource(): void
{
if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
self::markTestSkipped('Skipped due to setting of environment variable');
Expand All @@ -37,7 +37,7 @@ public function xtestURLImageSource(): void
$spreadsheet->disconnectWorksheets();
}

public function xtestURLImageSourceNotFound(): void
public function testURLImageSourceNotFound(): void
{
if (getenv('SKIP_URL_IMAGE_TEST') === '1') {
self::markTestSkipped('Skipped due to setting of environment variable');
Expand Down
Loading