Skip to content

Commit

Permalink
Using htmlspecialchars to fix issue PHPOffice#3145: this prevents the…
Browse files Browse the repository at this point in the history
… SimpleXMLElement error "unterminated entity reference" when HTML entities are present in a worksheet
  • Loading branch information
Robin Kopp committed Oct 27, 2022
1 parent c16d86d commit 3d53cb7
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/PhpSpreadsheet/Reader/Xlsx.php
Original file line number Diff line number Diff line change
Expand Up @@ -940,7 +940,7 @@ protected function loadSpreadsheetFromFile(string $filename): Spreadsheet
}
$node->addAttribute('sqref', $item->children(Namespaces::DATA_VALIDATIONS2)->sqref);
if (isset($item->formula1)) {
$node->addChild('formula1', $item->formula1->children(Namespaces::DATA_VALIDATIONS2)->f);
$node->addChild('formula1', htmlspecialchars($item->formula1->children(Namespaces::DATA_VALIDATIONS2)->f));
}
}
}
Expand Down
20 changes: 20 additions & 0 deletions tests/PhpSpreadsheetTests/Reader/Xlsx/Issue3145Test.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace PhpOffice\PhpSpreadsheetTests\Reader\Xlsx;

use PhpOffice\PhpSpreadsheet\IOFactory;
use PHPUnit\Framework\TestCase;

class Issue3145Test extends TestCase
{
public function testIssue3145(): void
{
$filename = 'tests/data/Reader/XLSX/issue.3145.xlsx';
$reader = IOFactory::createReader('Xlsx');
$spreadsheet = $reader->load($filename);
$sheet = $spreadsheet->getActiveSheet();

self::assertEquals('Headline A', $sheet->getCell('A1')->getValue());
self::assertEquals('Configdential B', $sheet->getCell('A2')->getValue());
}
}
Binary file added tests/data/Reader/XLSX/issue.3145.xlsx
Binary file not shown.

0 comments on commit 3d53cb7

Please sign in to comment.