Skip to content

Commit

Permalink
Merge pull request PHPOffice#4276 from oleibman/streamcontext
Browse files Browse the repository at this point in the history
Additional Context Options for https, Restore Disabled Tests
  • Loading branch information
oleibman authored Dec 14, 2024
2 parents 1e78397 + 92292e5 commit eccbcce
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 9 deletions.
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

0 comments on commit eccbcce

Please sign in to comment.