@@ -1521,9 +1521,10 @@ private function generateRow(Worksheet $worksheet, array $values, $row, $cellTyp
15211521 $ url = $ worksheet ->getHyperlink ($ coordinate )->getUrl ();
15221522 $ urlDecode1 = html_entity_decode ($ url , ENT_QUOTES | ENT_SUBSTITUTE , 'UTF-8 ' );
15231523 $ 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 )) {
15261526 $ cellData = htmlspecialchars ($ url , Settings::htmlEntityFlags ());
1527+ $ cellData = self ::replaceControlChars ($ cellData );
15271528 } else {
15281529 $ cellData = '<a href=" ' . htmlspecialchars ($ url , Settings::htmlEntityFlags ()) . '" title=" ' . htmlspecialchars ($ worksheet ->getHyperlink ($ coordinate )->getTooltip (), Settings::htmlEntityFlags ()) . '"> ' . $ cellData . '</a> ' ;
15291530 }
@@ -1568,6 +1569,20 @@ private function generateRow(Worksheet $worksheet, array $values, $row, $cellTyp
15681569 return $ html ;
15691570 }
15701571
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+
15711586 /**
15721587 * Takes array where of CSS properties / values and converts to CSS string.
15731588 *
0 commit comments