WordPress.org

Make WordPress Core

Opened 3 months ago

Closed 3 months ago

#50860 closed defect (bug) (fixed)

Fix duplicate array keys in Tests_Kses::test_wp_filter_post_kses_address method

Reported by: ediamin Owned by: SergeyBiryukov
Milestone: 5.6 Priority: normal
Severity: normal Version:
Component: Build/Test Tools Keywords: has-patch
Focuses: Cc:

Description

This is the current code

function test_wp_filter_post_kses_address() {
	global $allowedposttags;

	$attributes = array(
		'class' => 'classname',
		'id'    => 'id',
		'style' => 'color: red;',
		'style' => 'color: red',
		'style' => 'color: red; text-align:center',
		'style' => 'color: red; text-align:center;',
		'title' => 'title',
	);

	foreach ( $attributes as $name => $value ) {
		$string        = "<address $name='$value'>1 WordPress Avenue, The Internet.</address>";
		$expect_string = "<address $name='" . str_replace( '; ', ';', trim( $value, ';' ) ) . "'>1 WordPress Avenue, The Internet.</address>";
		$this->assertEquals( $expect_string, wp_kses( $string, $allowedposttags ) );
	}
}

Here you can see the $attributes array contains four duplicate style keys. So in practive, we are only testing for the last value of style that is color: red; text-align:center;.

This patch tries to fix this problem by separating test assertions for styles.

Attachments (1)

50860.diff (1.3 KB) - added by ediamin 3 months ago.

Download all attachments as: .zip

Change History (3)

@ediamin
3 months ago

#1 @SergeyBiryukov
3 months ago

  • Milestone changed from Awaiting Review to 5.6
  • Owner set to SergeyBiryukov
  • Status changed from new to reviewing

#2 @SergeyBiryukov
3 months ago

  • Resolution set to fixed
  • Status changed from reviewing to closed

In 48744:

Tests: Correct duplicate array keys in Tests_Kses::test_wp_filter_post_kses_address().

Previously, only the last style value was actually tested.

Props ediamin.
Fixes #50860.

Note: See TracTickets for help on using tickets.