Skip to content

Commit 0813667

Browse files
committed
Ditch regexp
1 parent ff59ffd commit 0813667

File tree

2 files changed

+265
-69
lines changed

2 files changed

+265
-69
lines changed

components/DataLiberation/Tests/CSSUrlProcessorTest.php

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22

33
use PHPUnit\Framework\TestCase;
44
use WordPress\DataLiberation\URL\CSSUrlProcessor;
5-
use WordPress\DataLiberation\URL\WPURL;
65

76
class CSSUrlProcessorTest extends TestCase {
87

@@ -144,6 +143,10 @@ public static function provider_test_css_escape_decoding() {
144143
'background: url(https://example.com/\\4E2D\\6587.png)',
145144
'https://example.com/中文.png',
146145
),
146+
'Multiple trailing whitespaces after the hex escape are preserved' => array(
147+
'background: url("https://example.com/test\\26 more.png")',
148+
'https://example.com/test& more.png',
149+
),
147150

148151
// Case insensitivity of hex digits
149152
'Lowercase hex digits' => array(
@@ -323,4 +326,16 @@ public function test_handles_data_uris() {
323326
$this->assertTrue( $processor->next_url() );
324327
$this->assertEquals( 'data:image/png;base64,iVBORw0KGgo=', $processor->get_raw_url() );
325328
}
329+
330+
public function test_handles_1mb_data_uri() {
331+
// Test with 1MB data URI using state machine parser
332+
// The parser can handle arbitrarily large URLs without PCRE limits
333+
$data_uri = 'data:image/png;base64,' . str_repeat( 'A', 2 * 1024 * 1024 );
334+
$css_value = 'background: url("' . $data_uri . '")';
335+
$processor = new CSSUrlProcessor( $css_value );
336+
337+
$this->assertTrue( $processor->next_url(), 'Failed to find URL in CSS' );
338+
$this->assertEquals( $data_uri, $processor->get_raw_url() );
339+
}
340+
326341
}

0 commit comments

Comments
 (0)