Skip to content
Open
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
35 changes: 35 additions & 0 deletions tests/phpunit/tests/html-api/wpHtmlProcessor-serialize.php
Original file line number Diff line number Diff line change
Expand Up @@ -853,4 +853,39 @@ public static function data_provider_normalize_special_leading_newline_cases():
),
);
}

/**
* Ensures that serialize_token() reflects enqueued attribute updates instead
* of emitting removed attributes as value-less attributes or omitting added ones.
*
* serialize_token() iterates the names from get_attribute_names_with_prefix( '' )
* but reads each value through get_attribute(). Before #64567 the name list did not
* reflect enqueued updates while the values did, so a removed attribute survived in
* the output as a boolean attribute and an added attribute was dropped entirely.
*
* @ticket 64567
*
* @covers WP_HTML_Processor::serialize_token
*/
public function test_serialize_token_reflects_enqueued_attribute_updates() {
$processor = WP_HTML_Processor::create_fragment( '<div onclick="alert(1)" class="x">Text</div>' );
$processor->next_tag();
$processor->remove_attribute( 'onclick' );

$this->assertSame(
'<div class="x">',
$processor->serialize_token(),
'An attribute enqueued for removal was serialized as a value-less attribute.'
);

$processor = WP_HTML_Processor::create_fragment( '<div class="x">Text</div>' );
$processor->next_tag();
$processor->set_attribute( 'id', 'new' );

$this->assertStringContainsString(
'id="new"',
$processor->serialize_token(),
'An attribute enqueued via set_attribute() was not serialized.'
);
}
}
Loading