Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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() );
}
}
12 changes: 6 additions & 6 deletions components/DataLiberation/Tests/css-test-cases.json
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,7 @@
"startIndex": 0,
"endIndex": 4,
"normalized": "\"foo",
"value": "foo"
"value": null
},
{
"type": "whitespace-token",
Expand All @@ -253,7 +253,7 @@
"startIndex": 5,
"endIndex": 6,
"normalized": "\"",
"value": ""
"value": null
},
{
"type": "whitespace-token",
Expand Down Expand Up @@ -295,7 +295,7 @@
"startIndex": 0,
"endIndex": 4,
"normalized": "\"foo",
"value": "foo"
"value": null
},
{
"type": "whitespace-token",
Expand All @@ -311,7 +311,7 @@
"startIndex": 6,
"endIndex": 7,
"normalized": "\"",
"value": ""
"value": null
},
{
"type": "whitespace-token",
Expand Down Expand Up @@ -353,7 +353,7 @@
"startIndex": 0,
"endIndex": 7,
"normalized": "\"aa𐀀",
"value": "aa𐀀"
"value": null
},
{
"type": "whitespace-token",
Expand Down Expand Up @@ -4251,7 +4251,7 @@
"startIndex": 0,
"endIndex": 3,
"normalized": "\"fo",
"value": "fo"
"value": null
},
{
"type": "whitespace-token",
Expand Down
Loading