|
2 | 2 |
|
3 | 3 | namespace PhpOffice\PhpSpreadsheet\Writer; |
4 | 4 |
|
| 5 | +use Composer\Pcre\Preg; |
5 | 6 | use PhpOffice\PhpSpreadsheet\Calculation\Calculation; |
6 | 7 | use PhpOffice\PhpSpreadsheet\Cell\Cell; |
7 | 8 | use PhpOffice\PhpSpreadsheet\Cell\Coordinate; |
@@ -646,13 +647,13 @@ private function writeImageInCell(string $coordinates): string |
646 | 647 | $filename = $drawing->getPath(); |
647 | 648 |
|
648 | 649 | // Strip off eventual '.' |
649 | | - $filename = (string) preg_replace('/^[.]/', '', $filename); |
| 650 | + $filename = Preg::replace('/^[.]/', '', $filename); |
650 | 651 |
|
651 | 652 | // Prepend images root |
652 | 653 | $filename = $this->getImagesRoot() . $filename; |
653 | 654 |
|
654 | 655 | // Strip off eventual '.' if followed by non-/ |
655 | | - $filename = (string) preg_replace('@^[.]([^/])@', '$1', $filename); |
| 656 | + $filename = Preg::replace('@^[.]([^/])@', '$1', $filename); |
656 | 657 |
|
657 | 658 | // Convert UTF8 data to PCDATA |
658 | 659 | $filename = htmlspecialchars($filename, Settings::htmlEntityFlags()); |
@@ -1411,7 +1412,7 @@ private function generateRowCellData(Worksheet $worksheet, null|Cell|string $cel |
1411 | 1412 |
|
1412 | 1413 | // Converts the cell content so that spaces occuring at beginning of each new line are replaced by |
1413 | 1414 | // Example: " Hello\n to the world" is converted to " Hello\n to the world" |
1414 | | - $cellData = (string) preg_replace('/(?m)(?:^|\\G) /', ' ', $cellData); |
| 1415 | + $cellData = Preg::replace('/(?m)(?:^|\\G) /', ' ', $cellData); |
1415 | 1416 |
|
1416 | 1417 | // convert newline "\n" to '<br>' |
1417 | 1418 | $cellData = nl2br($cellData); |
@@ -1587,9 +1588,9 @@ private function generateRow(Worksheet $worksheet, array $values, int $row, stri |
1587 | 1588 | if ($worksheet->hyperlinkExists($coordinate) && !$worksheet->getHyperlink($coordinate)->isInternal()) { |
1588 | 1589 | $url = $worksheet->getHyperlink($coordinate)->getUrl(); |
1589 | 1590 | $urlDecode1 = html_entity_decode($url, ENT_QUOTES | ENT_SUBSTITUTE, 'UTF-8'); |
1590 | | - $urlTrim = preg_replace('/^\\s+/u', '', $urlDecode1) ?? $urlDecode1; |
1591 | | - $parseScheme = preg_match('/^([\\w\\s]+):/u', strtolower($urlTrim), $matches); |
1592 | | - if ($parseScheme === 1 && !in_array($matches[1], ['http', 'https', 'file', 'ftp', 's3'], true)) { |
| 1591 | + $urlTrim = Preg::replace('/^\\s+/u', '', $urlDecode1); |
| 1592 | + $parseScheme = Preg::isMatch('/^([\\w\\s]+):/u', strtolower($urlTrim), $matches); |
| 1593 | + if ($parseScheme && !in_array($matches[1], ['http', 'https', 'file', 'ftp', 's3'], true)) { |
1593 | 1594 | $cellData = htmlspecialchars($url, Settings::htmlEntityFlags()); |
1594 | 1595 | } else { |
1595 | 1596 | $cellData = '<a href="' . htmlspecialchars($url, Settings::htmlEntityFlags()) . '" title="' . htmlspecialchars($worksheet->getHyperlink($coordinate)->getTooltip(), Settings::htmlEntityFlags()) . '">' . $cellData . '</a>'; |
@@ -1738,8 +1739,8 @@ public static function formatColorStatic(string $value, string $format): string |
1738 | 1739 | $matches = []; |
1739 | 1740 |
|
1740 | 1741 | $color_regex = '/^\\[[a-zA-Z]+\\]/'; |
1741 | | - if (preg_match($color_regex, $format, $matches)) { |
1742 | | - $color = str_replace(['[', ']'], '', $matches[0]); |
| 1742 | + if (Preg::isMatch($color_regex, $format, $matches)) { |
| 1743 | + $color = str_replace(['[', ']'], '', $matches[0]); // @phpstan-ignore-line |
1743 | 1744 | $color = strtolower($color); |
1744 | 1745 | } |
1745 | 1746 |
|
|
0 commit comments