Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions components/DataLiberation/CSS/class-cssprocessor.php
Original file line number Diff line number Diff line change
Expand Up @@ -668,7 +668,7 @@ public function get_unnormalized_token(): ?string {
* - For strings/URLs: the decoded string value
* - For other tokens: null
*
* @see https://www.w3.org/TR/css-syntax-3/#token-value
* @see https://www.w3.org/TR/css-syntax-3/#tokenization
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This URL used a fragment that isn't present. The updated URL links to an appropriate section.

* @return string|null
*/
public function get_token_value() {
Expand Down Expand Up @@ -699,15 +699,13 @@ public function get_token_value() {
break;

case self::TOKEN_STRING:
case self::TOKEN_BAD_STRING:
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is the essential fix 👍

case self::TOKEN_URL:
// Decode and cache the string/URL value.
if ( null !== $this->token_value_starts_at && null !== $this->token_value_length ) {
$this->token_value = $this->decode_string_or_url(
$this->token_value_starts_at,
$this->token_value_length
);
$this->token_value = $this->token_value;
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This does look like a redundant line 👍

} else {
$this->token_value = null;
}
Expand Down
15 changes: 15 additions & 0 deletions components/DataLiberation/Tests/CSSProcessorTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -1541,4 +1541,19 @@ public function test_ident_start_codepoint_bounds_check(): void {
);
$this->assertSame( $expected_tokens, $actual_tokens );
}

/**
* Tests that bad-string-token returns null for get_token_value().
*
* Per the CSS spec, bad-string-token has no associated data.
*
* @see https://www.w3.org/TR/css-syntax-3/#tokenization
*/
public function test_bad_string_token_value_is_null(): void {
// A bad-string-token is produced when a string is broken by a newline.
$processor = CSSProcessor::create( "'str\ning'" );
$processor->next_token();
$this->assertSame( CSSProcessor::TOKEN_BAD_STRING, $processor->get_token_type() );
$this->assertNull( $processor->get_token_value() );
}
}
Loading