diff --git a/components/DataLiberation/CSS/class-cssprocessor.php b/components/DataLiberation/CSS/class-cssprocessor.php index cacb48b4..e7f50adb 100644 --- a/components/DataLiberation/CSS/class-cssprocessor.php +++ b/components/DataLiberation/CSS/class-cssprocessor.php @@ -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 * @return string|null */ public function get_token_value() { @@ -699,7 +699,6 @@ public function get_token_value() { break; case self::TOKEN_STRING: - case self::TOKEN_BAD_STRING: case self::TOKEN_URL: // Decode and cache the string/URL value. if ( null !== $this->token_value_starts_at && null !== $this->token_value_length ) { @@ -707,7 +706,6 @@ public function get_token_value() { $this->token_value_starts_at, $this->token_value_length ); - $this->token_value = $this->token_value; } else { $this->token_value = null; } diff --git a/components/DataLiberation/Tests/CSSProcessorTest.php b/components/DataLiberation/Tests/CSSProcessorTest.php index ed164ac2..a6f7f7f3 100644 --- a/components/DataLiberation/Tests/CSSProcessorTest.php +++ b/components/DataLiberation/Tests/CSSProcessorTest.php @@ -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() ); + } } diff --git a/components/DataLiberation/Tests/css-test-cases.json b/components/DataLiberation/Tests/css-test-cases.json index a1c10081..c1ead99f 100644 --- a/components/DataLiberation/Tests/css-test-cases.json +++ b/components/DataLiberation/Tests/css-test-cases.json @@ -237,7 +237,7 @@ "startIndex": 0, "endIndex": 4, "normalized": "\"foo", - "value": "foo" + "value": null }, { "type": "whitespace-token", @@ -253,7 +253,7 @@ "startIndex": 5, "endIndex": 6, "normalized": "\"", - "value": "" + "value": null }, { "type": "whitespace-token", @@ -295,7 +295,7 @@ "startIndex": 0, "endIndex": 4, "normalized": "\"foo", - "value": "foo" + "value": null }, { "type": "whitespace-token", @@ -311,7 +311,7 @@ "startIndex": 6, "endIndex": 7, "normalized": "\"", - "value": "" + "value": null }, { "type": "whitespace-token", @@ -353,7 +353,7 @@ "startIndex": 0, "endIndex": 7, "normalized": "\"aa𐀀", - "value": "aa𐀀" + "value": null }, { "type": "whitespace-token", @@ -4251,7 +4251,7 @@ "startIndex": 0, "endIndex": 3, "normalized": "\"fo", - "value": "fo" + "value": null }, { "type": "whitespace-token",