mirror of
https://github.com/PHPOffice/PhpSpreadsheet.git
synced 2026-09-14 03:56:40 +00:00
Excel 2003 Allows Html Entities
Fix #2157. Excel 2003 format allows some things which a real Xml parser would reject. In particular, it permits Html entities, and leading whitespace. Change Xml Reader to do likewise.
This commit is contained in:
@@ -44,6 +44,18 @@ class Xml extends BaseReader
|
||||
{
|
||||
parent::__construct();
|
||||
$this->securityScanner = XmlScanner::getInstance($this);
|
||||
/** @var callable */
|
||||
$unentity = [self::class, 'unentity'];
|
||||
$this->securityScanner->setAdditionalCallback($unentity);
|
||||
}
|
||||
|
||||
public static function unentity(string $contents): string
|
||||
{
|
||||
$contents = preg_replace('/&(amp|lt|gt|quot|apos);/', "\u{fffe}\u{feff}\$1;", trim($contents)) ?? $contents;
|
||||
$contents = html_entity_decode($contents, ENT_NOQUOTES | ENT_SUBSTITUTE | ENT_HTML401, 'UTF-8');
|
||||
$contents = str_replace("\u{fffe}\u{feff}", '&', $contents);
|
||||
|
||||
return $contents;
|
||||
}
|
||||
|
||||
private string $fileContents = '';
|
||||
|
||||
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
declare(strict_types=1);
|
||||
|
||||
namespace PhpOffice\PhpSpreadsheetTests\Reader\Xml;
|
||||
|
||||
use PhpOffice\PhpSpreadsheet\Reader\Xml as XmlReader;
|
||||
use PHPUnit\Framework\TestCase;
|
||||
|
||||
class HtmlEntitiesLoadTest extends TestCase
|
||||
{
|
||||
public static function testIssue2157(): void
|
||||
{
|
||||
$infile = 'tests/data/Reader/Xml/issue.2157.small.xml';
|
||||
$contents = (string) file_get_contents($infile);
|
||||
self::assertSame("\t", substr($contents, 0, 1));
|
||||
self::assertStringContainsString('Τ', $contents);
|
||||
self::assertStringContainsString('</br>', $contents);
|
||||
self::assertStringNotContainsString('Τ', $contents); // that's a Tau, not T
|
||||
self::assertStringNotContainsString('</br>', $contents);
|
||||
$reader = new XmlReader();
|
||||
$spreadsheet = $reader->load($infile);
|
||||
$sheet = $spreadsheet->getActiveSheet();
|
||||
self::assertSame('Τέλεια όραση χωρίς γυαλιά', $sheet->getCell('E2')->getValue());
|
||||
$g2 = $sheet->getCell('G2')->getValue();
|
||||
self::assertStringContainsString('</br>', $g2);
|
||||
$spreadsheet->disconnectWorksheets();
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,109 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<Workbook xmlns="urn:schemas-microsoft-com:office:spreadsheet" xmlns:x="urn:schemas-microsoft-com:office:excel" xmlns:ss="urn:schemas-microsoft-com:office:spreadsheet" xmlns:html="http://www.w3.org/TR/REC-html40">
|
||||
<Worksheet ss:Name="ProductsAPIData">
|
||||
<Table>
|
||||
<Row>
|
||||
<Cell><Data ss:Type="String">id</Data></Cell>
|
||||
<Cell><Data ss:Type="String">isbn</Data></Cell>
|
||||
<Cell><Data ss:Type="String">barcode</Data></Cell>
|
||||
<Cell><Data ss:Type="String">url</Data></Cell>
|
||||
<Cell><Data ss:Type="String">title</Data></Cell>
|
||||
<Cell><Data ss:Type="String">short_description</Data></Cell>
|
||||
<Cell><Data ss:Type="String">description</Data></Cell>
|
||||
<Cell><Data ss:Type="String">category</Data></Cell>
|
||||
<Cell><Data ss:Type="String">weight</Data></Cell>
|
||||
<Cell><Data ss:Type="String">pages</Data></Cell>
|
||||
<Cell><Data ss:Type="String">publication_date</Data></Cell>
|
||||
<Cell><Data ss:Type="String">3d_photo</Data></Cell>
|
||||
<Cell><Data ss:Type="String">photo</Data></Cell>
|
||||
<Cell><Data ss:Type="String">pdf_preview</Data></Cell>
|
||||
<Cell><Data ss:Type="String">flipping_book</Data></Cell>
|
||||
<Cell><Data ss:Type="String">offer</Data></Cell>
|
||||
<Cell><Data ss:Type="String">active</Data></Cell>
|
||||
<Cell><Data ss:Type="String">availability</Data></Cell>
|
||||
<Cell><Data ss:Type="String">size</Data></Cell>
|
||||
<Cell><Data ss:Type="String">country</Data></Cell>
|
||||
<Cell><Data ss:Type="String">subject</Data></Cell>
|
||||
<Cell><Data ss:Type="String">retail_price</Data></Cell>
|
||||
<Cell><Data ss:Type="String">wholesale_price</Data></Cell>
|
||||
<Cell><Data ss:Type="String">ebook-isbn</Data></Cell>
|
||||
<Cell><Data ss:Type="String">ebook-barcode</Data></Cell>
|
||||
<Cell><Data ss:Type="String">ebook-retail_price</Data></Cell>
|
||||
<Cell><Data ss:Type="String">ebook-wholesale_price</Data></Cell>
|
||||
<Cell><Data ss:Type="String">ebook-urn</Data></Cell>
|
||||
<Cell><Data ss:Type="String">ebook-drm</Data></Cell>
|
||||
<Cell><Data ss:Type="String">ebook-format</Data></Cell>
|
||||
<Cell><Data ss:Type="String">ebook-active</Data></Cell>
|
||||
<Cell><Data ss:Type="String">author1-name</Data></Cell>
|
||||
<Cell><Data ss:Type="String">author1-url</Data></Cell>
|
||||
<Cell><Data ss:Type="String">author1-photo</Data></Cell>
|
||||
<Cell><Data ss:Type="String">author1-description</Data></Cell>
|
||||
<Cell><Data ss:Type="String">author1-link</Data></Cell>
|
||||
<Cell><Data ss:Type="String">author2-name</Data></Cell>
|
||||
<Cell><Data ss:Type="String">author2-url</Data></Cell>
|
||||
<Cell><Data ss:Type="String">author2-photo</Data></Cell>
|
||||
<Cell><Data ss:Type="String">author2-description</Data></Cell>
|
||||
<Cell><Data ss:Type="String">author2-link</Data></Cell>
|
||||
<Cell><Data ss:Type="String">translator-name</Data></Cell>
|
||||
<Cell><Data ss:Type="String">translator-photo</Data></Cell>
|
||||
<Cell><Data ss:Type="String">translator-description</Data></Cell>
|
||||
<Cell><Data ss:Type="String">editor-name</Data></Cell>
|
||||
<Cell><Data ss:Type="String">editor-photo</Data></Cell>
|
||||
<Cell><Data ss:Type="String">editor-description</Data></Cell>
|
||||
</Row>
|
||||
<Row>
|
||||
<Cell><Data ss:Type="String">2</Data></Cell>
|
||||
<Cell><Data ss:Type="String">978-960-364-004-2</Data></Cell>
|
||||
<Cell><Data ss:Type="String">9789603640042</Data></Cell>
|
||||
<Cell><Data ss:Type="String">https://www.dioptra.gr/vivlio/ygeia-diatrofi/teleia-orasi-xoris-gualia/</Data></Cell>
|
||||
<Cell><Data ss:Type="String">Τέλεια όραση χωρίς γυαλιά</Data></Cell>
|
||||
<Cell><Data ss:Type="String">Με τη μέθοδο Bates βελτιώνουμε την όρασή μας ή προλαμβάνουμε τα προβλήματα του πιο ευαίσθητου οργάνου του σώματος – των ματιών.</Data></Cell>
|
||||
<Cell><Data ss:Type="String">Φορώντας τα γυαλιά «καταλαβαίνεις αμέσως τη διαφορά». Δεν νοιάζεσαι αν θα χρειαστείς αργότερα πιο δυνατούς φακούς, γιατί νομίζεις ότι δεν υπάρχει θεραπεία για τα ταλαιπωρημένα μάτια.</br>
|
||||
Κι όμως τα πράγματα δεν είναι έτσι.</br>
|
||||
Οι περισσότεροι από αυτούς που φορούν γυαλιά θα μπορούσαν να τα είχαν αποφύγει. Ακόμα και τώρα μπορούν να βελτιώσουν την όρασή τους με τη μέθοδο Bates.</br>
|
||||
Η μέθοδος Bates είναι μια σειρά ασκήσεων και τεχνικών που χαλαρώνουν τους οφθαλμολογικούς μυς και τους επανεκπαιδεύουν να εστιάζουν αποτελεσματικά τις φωτεινές ακτίνες που εισέρχονται στο μάτι, επιτρέποντάς μας να βλέπουμε καλά και καθαρά χωρίς γυαλιά.</br>
|
||||
Εφαρμόστε σήμερα κιόλας, τη μέθοδο Bates για να βελτιώσετε την όρασή σας ή να προλάβετε τα προβλήματα του πιο ευαίσθητου οργάνου του σώματος – των ματιών σας.</br></Data></Cell>
|
||||
<Cell><Data ss:Type="String">Υγεία - Διατροφή</Data></Cell>
|
||||
<Cell><Data ss:Type="String">0.272</Data></Cell>
|
||||
<Cell><Data ss:Type="String">160</Data></Cell>
|
||||
<Cell><Data ss:Type="String">2002-06-03 00:00:00</Data></Cell>
|
||||
<Cell><Data ss:Type="String">https://www.dioptra.gr/Images/Products/004_list.jpg</Data></Cell>
|
||||
<Cell><Data ss:Type="String">https://www.dioptra.gr/Images/Products/004.jpg</Data></Cell>
|
||||
<Cell><Data ss:Type="String"></Data></Cell>
|
||||
<Cell><Data ss:Type="String"></Data></Cell>
|
||||
<Cell><Data ss:Type="String">0</Data></Cell>
|
||||
<Cell><Data ss:Type="String">1</Data></Cell>
|
||||
<Cell><Data ss:Type="String">1</Data></Cell>
|
||||
<Cell><Data ss:Type="String">140 x 205</Data></Cell>
|
||||
<Cell><Data ss:Type="String">Ελλάδα</Data></Cell>
|
||||
<Cell><Data ss:Type="String">-</Data></Cell>
|
||||
<Cell><Data ss:Type="String">13.19</Data></Cell>
|
||||
<Cell><Data ss:Type="String">12.44</Data></Cell>
|
||||
<Cell><Data ss:Type="String">-</Data></Cell>
|
||||
<Cell><Data ss:Type="String">-</Data></Cell>
|
||||
<Cell><Data ss:Type="String">-</Data></Cell>
|
||||
<Cell><Data ss:Type="String">-</Data></Cell>
|
||||
<Cell><Data ss:Type="String">-</Data></Cell>
|
||||
<Cell><Data ss:Type="String">-</Data></Cell>
|
||||
<Cell><Data ss:Type="String">-</Data></Cell>
|
||||
<Cell><Data ss:Type="String">-</Data></Cell>
|
||||
<Cell><Data ss:Type="String">George Kypreotakis</Data></Cell>
|
||||
<Cell><Data ss:Type="String">https://www.dioptra.gr/suggrafeas/171/</Data></Cell>
|
||||
<Cell><Data ss:Type="String"></Data></Cell>
|
||||
<Cell><Data ss:Type="String"></Data></Cell>
|
||||
<Cell><Data ss:Type="String"></Data></Cell>
|
||||
<Cell><Data ss:Type="String">-</Data></Cell>
|
||||
<Cell><Data ss:Type="String">-</Data></Cell>
|
||||
<Cell><Data ss:Type="String">-</Data></Cell>
|
||||
<Cell><Data ss:Type="String">-</Data></Cell>
|
||||
<Cell><Data ss:Type="String">-</Data></Cell>
|
||||
<Cell><Data ss:Type="String">-</Data></Cell>
|
||||
<Cell><Data ss:Type="String">-</Data></Cell>
|
||||
<Cell><Data ss:Type="String">-</Data></Cell>
|
||||
<Cell><Data ss:Type="String">-</Data></Cell>
|
||||
<Cell><Data ss:Type="String">-</Data></Cell>
|
||||
<Cell><Data ss:Type="String">-</Data></Cell>
|
||||
</Row>
|
||||
</Table>
|
||||
</Worksheet>
|
||||
</Workbook>
|
||||
Reference in New Issue
Block a user