@@ -1521,9 +1521,10 @@ private function generateRow(Worksheet $worksheet, array $values, $row, $cellTyp
1521
1521
$ url = $ worksheet ->getHyperlink ($ coordinate )->getUrl ();
1522
1522
$ urlDecode1 = html_entity_decode ($ url , ENT_QUOTES | ENT_SUBSTITUTE , 'UTF-8 ' );
1523
1523
$ urlTrim = preg_replace ('/^ \\s+/u ' , '' , $ urlDecode1 ) ?? $ urlDecode1 ;
1524
- $ parseScheme = preg_match ('/^([ \\w \\s]+):/u ' , strtolower ($ urlTrim ), $ matches );
1525
- if ($ parseScheme === 1 && !in_array ($ matches [1 ], ['http ' , 'https ' , 'file ' , 'ftp ' , 's3 ' ], true )) {
1524
+ $ parseScheme = preg_match ('/^([ \\w \\s \\ x00- \\ x1f ]+):/u ' , strtolower ($ urlTrim ), $ matches );
1525
+ if ($ parseScheme === 1 && !in_array ($ matches [1 ], ['http ' , 'https ' , 'file ' , 'ftp ' , 'mailto ' , ' s3 ' ], true )) {
1526
1526
$ cellData = htmlspecialchars ($ url , Settings::htmlEntityFlags ());
1527
+ $ cellData = self ::replaceControlChars ($ cellData );
1527
1528
} else {
1528
1529
$ cellData = '<a href=" ' . htmlspecialchars ($ url , Settings::htmlEntityFlags ()) . '" title=" ' . htmlspecialchars ($ worksheet ->getHyperlink ($ coordinate )->getTooltip (), Settings::htmlEntityFlags ()) . '"> ' . $ cellData . '</a> ' ;
1529
1530
}
@@ -1568,6 +1569,20 @@ private function generateRow(Worksheet $worksheet, array $values, $row, $cellTyp
1568
1569
return $ html ;
1569
1570
}
1570
1571
1572
+ private static function replaceNonAscii (array $ matches ): string
1573
+ {
1574
+ return '&# ' . mb_ord ($ matches [0 ], 'UTF-8 ' ) . '; ' ;
1575
+ }
1576
+
1577
+ private static function replaceControlChars (string $ convert ): string
1578
+ {
1579
+ return (string ) preg_replace_callback (
1580
+ '/[ \\x00- \\x1f]/ ' ,
1581
+ [self ::class, 'replaceNonAscii ' ],
1582
+ $ convert
1583
+ );
1584
+ }
1585
+
1571
1586
/**
1572
1587
* Takes array where of CSS properties / values and converts to CSS string.
1573
1588
*
0 commit comments