Skip to content

Commit ceb702c

Browse files
bsweeneyJay Panjwani
authored andcommitted
Retry data-URI parsing failure after removing whitespace
Though not valid per the spec to include whitespace in the non-data portion of the data-URI, browser do perform a similar operation. The whitespace removal is done after initial failure in order to minimize impact on documents with a correcty formatted data-URIs. fixes dompdf#1386
1 parent 60e0af1 commit ceb702c

File tree

1 file changed

+7
-2
lines changed

1 file changed

+7
-2
lines changed

src/Helpers.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -287,8 +287,13 @@ public static function is_percent($value): bool
287287
*/
288288
public static function parse_data_uri($data_uri)
289289
{
290-
if (!preg_match('/^data:(?P<mime>[a-z0-9\/+-.]+)(;charset=(?P<charset>[a-z0-9-])+)?(?P<base64>;base64)?\,(?P<data>.*)?/is', $data_uri, $match)) {
291-
return false;
290+
$expression = '/^data:(?P<mime>[a-z0-9\/+-.]+)(;charset=(?P<charset>[a-z0-9-])+)?(?P<base64>;base64)?\,(?P<data>.*)?/is';
291+
if (!preg_match($expression, $data_uri, $match)) {
292+
$parts = explode(",", $data_uri);
293+
$parts[0] = preg_replace('/\\s/', '', $parts[0]);
294+
if (preg_match('/\\s/', $data_uri) && !preg_match($expression, implode(",", $parts), $match)) {
295+
return false;
296+
}
292297
}
293298

294299
$match['data'] = rawurldecode($match['data']);

0 commit comments

Comments
 (0)