Skip to content

Commit 7a64cdf

Browse files
committed
Fix unit tests
1 parent 015ea44 commit 7a64cdf

File tree

3 files changed

+24
-25
lines changed

3 files changed

+24
-25
lines changed

components/DataLiberation/Tests/BlockMarkupUrlProcessorTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -413,7 +413,7 @@ public static function provider_test_css_url_replacement() {
413413
'Replace single-quoted URL' => array(
414414
'<div style="background: url(\'https://old.com/image.png\');"></div>',
415415
'https://new.com/image.png',
416-
'<div style="background: url(\'https://new.com/image.png\');"></div>',
416+
'<div style="background: url(&quot;https://new.com/image.png&quot;);"></div>',
417417
),
418418
'Replace relative URL' => array(
419419
'<div style="background: url(&quot;/old/path.png&quot;);"></div>',

components/DataLiberation/Tests/CSSUrlProcessorTest.php

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,7 @@ public static function provider_test_url_replacement() {
344344
'Replace single-quoted URL' => array(
345345
'input' => "background: url('https://old.com/image.png')",
346346
'new_url' => 'https://new.com/image.png',
347-
'expected' => "background: url('https://new.com/image.png')",
347+
'expected' => "background: url(\u{22}https://new.com/image.png\u{22})",
348348
),
349349
'Replace unquoted URL (outputs quoted)' => array(
350350
'input' => 'background: url(https://old.com/image.png)',
@@ -360,7 +360,7 @@ public static function provider_test_url_replacement() {
360360
'Sets new URL with single quotes in single-quoted string' => array(
361361
'input' => "background: url('https://old.com/old.png')",
362362
'new_url' => "https://example.com/path'with'quotes.png",
363-
'expected' => "background: url('https://example.com/path'with'quotes.png')",
363+
'expected' => "background: url(\u{22}https://example.com/path'with'quotes.png\u{22})",
364364
// Single quotes not escaped in single-quoted context
365365
),
366366
'Sets new URL with backslashes in path' => array(
@@ -522,7 +522,7 @@ public function test_comprehensive_url_replacement_in_complex_css() {
522522
.card {
523523
/* Multiple URLs in a single property */
524524
background: linear-gradient(rgba(0,0,0,0.5), rgba(0,0,0,0.5)),
525-
url('https://replaced.test/url-2'),
525+
url("https://replaced.test/url-2"),
526526
url("https://replaced.test/url-3");
527527
}
528528
@@ -537,7 +537,7 @@ public function test_comprehensive_url_replacement_in_complex_css() {
537537
}
538538
539539
.cursor {
540-
cursor: url('https://replaced.test/url-5'), auto;
540+
cursor: url("https://replaced.test/url-5"), auto;
541541
}
542542
543543
.content::before {

components/DataLiberation/URL/class-cssprocessor.php

Lines changed: 19 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -838,27 +838,26 @@ public function get_token_value_length(): ?int {
838838
* @return bool Whether the value was successfully updated.
839839
*/
840840
public function set_token_value( string $new_value ): bool {
841-
// Only URL tokens are currently supported.
842-
if ( self::TOKEN_URL !== $this->token_type ) {
843-
return false;
844-
}
845-
846-
// Ensure we have valid token value boundaries.
847-
if ( null === $this->token_value_starts_at || null === $this->token_value_length ) {
848-
return false;
841+
// Only URL and string tokens are currently supported.
842+
switch ($this->token_type) {
843+
case self::TOKEN_URL:
844+
$this->lexical_updates[] = array(
845+
'start' => $this->token_value_starts_at,
846+
'length' => $this->token_value_length,
847+
'text' => $this->escape_url_value( $new_value ),
848+
);
849+
return true;
850+
case self::TOKEN_STRING:
851+
$this->lexical_updates[] = array(
852+
'start' => $this->token_starts_at,
853+
'length' => $this->token_length,
854+
'text' => $this->escape_url_value( $new_value ),
855+
);
856+
return true;
857+
default:
858+
_doing_it_wrong( __METHOD__, 'set_token_value() only supports URL and string tokens. Got token type: ' . $this->token_type, '1.0.0' );
859+
return false;
849860
}
850-
851-
// Escape the URL value for unquoted URL syntax.
852-
$escaped_value = $this->escape_url_value( $new_value );
853-
854-
// Queue the lexical update.
855-
$this->lexical_updates[] = array(
856-
'start' => $this->token_value_starts_at,
857-
'length' => $this->token_value_length,
858-
'text' => $escaped_value,
859-
);
860-
861-
return true;
862861
}
863862

864863
/**

0 commit comments

Comments
 (0)