| @@ -1,8 +1,9 @@ | ||
| 1 | 1 | <?php |
| 2 | 2 | |
| 3 | 3 | namespace TablePress\PhpOffice\PhpSpreadsheet\Reader; |
| 4 | 4 | |
| 5 | +use TablePress\Composer\Pcre\Preg; | |
| 5 | 6 | use DateTime; |
| 6 | 7 | use DateTimeZone; |
| 7 | 8 | use TablePress\PhpOffice\PhpSpreadsheet\Cell\AddressHelper; |
| 8 | 9 | use TablePress\PhpOffice\PhpSpreadsheet\Cell\AddressRange; |
| @@ -52,11 +53,16 @@ | ||
| 52 | 53 | } |
| 53 | 54 | |
| 54 | 55 | public static function unentity(string $contents): string |
| 55 | 56 | { |
| 56 | - $contents = preg_replace('/&(amp|lt|gt|quot|apos);/', "\u{fffe}\u{feff}\$1;", trim($contents)) ?? $contents; | |
| 57 | + // fffe is invalid, replace with replacement char | |
| 58 | + $contents = str_replace("\u{fffe}", "\u{fffd}", $contents); | |
| 59 | + // use positive lookahead to "protect" valid xml entities | |
| 60 | + $contents = Preg::replace('/&(?=(?:amp|lt|gt|quot|apos|#[0-9]+|#x[0-9a-fA-F]+);)/', "\u{fffe}", trim($contents)); | |
| 61 | + // now decode remaining html entities | |
| 57 | 62 | $contents = html_entity_decode($contents, ENT_NOQUOTES | ENT_SUBSTITUTE | ENT_HTML401, 'UTF-8'); |
| 58 | - $contents = str_replace("\u{fffe}\u{feff}", '&', $contents); | |
| 63 | + // Escape remaining ampersands, restore those which were replaced with fffe | |
| 64 | + $contents = str_replace(['&', "\u{fffe}"], ['&', '&'], $contents); | |
| 59 | 65 | |
| 60 | 66 | return $contents; |
| 61 | 67 | } |
| 62 | 68 | |
| @@ -650,9 +656,9 @@ | ||
| 650 | 656 | } |
| 651 | 657 | } |
| 652 | 658 | $rangeCalculated = false; |
| 653 | 659 | if (isset($xmlX->WorksheetOptions->Panes->Pane->RangeSelection)) { |
| 654 | - if (1 === preg_match('/^R(\d+)C(\d+):R(\d+)C(\d+)$/', (string) $xmlX->WorksheetOptions->Panes->Pane->RangeSelection, $selectionMatches)) { | |
| 660 | + if (Preg::isMatch('/^R(\d+)C(\d+):R(\d+)C(\d+)$/', (string) $xmlX->WorksheetOptions->Panes->Pane->RangeSelection, $selectionMatches)) { | |
| 655 | 661 | $selectedCell = Coordinate::stringFromColumnIndex((int) $selectionMatches[2]) |
| 656 | 662 | . $selectionMatches[1] |
| 657 | 663 | . ':' |
| 658 | 664 | . Coordinate::stringFromColumnIndex((int) $selectionMatches[4]) |