@@ -1528,9 +1528,10 @@ private function generateRow(Worksheet $worksheet, array $values, int $row, stri
15281528 $ url = $ worksheet ->getHyperlink ($ coordinate )->getUrl ();
15291529 $ urlDecode1 = html_entity_decode ($ url , ENT_QUOTES | ENT_SUBSTITUTE , 'UTF-8 ' );
15301530 $ urlTrim = preg_replace ('/^ \\s+/u ' , '' , $ urlDecode1 ) ?? $ urlDecode1 ;
1531- $ parseScheme = preg_match ('/^([ \\w \\s]+):/u ' , strtolower ($ urlTrim ), $ matches );
1532- if ($ parseScheme === 1 && !in_array ($ matches [1 ], ['http ' , 'https ' , 'file ' , 'ftp ' , 's3 ' ], true )) {
1531+ $ parseScheme = preg_match ('/^([ \\w \\s \\ x00- \\ x1f ]+):/u ' , strtolower ($ urlTrim ), $ matches );
1532+ if ($ parseScheme === 1 && !in_array ($ matches [1 ], ['http ' , 'https ' , 'file ' , 'ftp ' , 'mailto ' , ' s3 ' ], true )) {
15331533 $ cellData = htmlspecialchars ($ url , Settings::htmlEntityFlags ());
1534+ $ cellData = self ::replaceControlChars ($ cellData );
15341535 } else {
15351536 $ cellData = '<a href=" ' . htmlspecialchars ($ url , Settings::htmlEntityFlags ()) . '" title=" ' . htmlspecialchars ($ worksheet ->getHyperlink ($ coordinate )->getTooltip (), Settings::htmlEntityFlags ()) . '"> ' . $ cellData . '</a> ' ;
15361537 }
@@ -1580,6 +1581,20 @@ private function generateRow(Worksheet $worksheet, array $values, int $row, stri
15801581 return $ html ;
15811582 }
15821583
1584+ private static function replaceNonAscii (array $ matches ): string
1585+ {
1586+ return '&# ' . mb_ord ($ matches [0 ], 'UTF-8 ' ) . '; ' ;
1587+ }
1588+
1589+ private static function replaceControlChars (string $ convert ): string
1590+ {
1591+ return (string ) preg_replace_callback (
1592+ '/[ \\x00- \\x1f]/ ' ,
1593+ [self ::class, 'replaceNonAscii ' ],
1594+ $ convert
1595+ );
1596+ }
1597+
15831598 /**
15841599 * Takes array where of CSS properties / values and converts to CSS string.
15851600 */
0 commit comments