Skip to content

Commit 35cc667

Browse files
committed
Preserve more Core behaviors
1 parent 804969a commit 35cc667

2 files changed

Lines changed: 65 additions & 2 deletions

File tree

src/wp-includes/formatting.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1079,8 +1079,8 @@ function _esc_attr_single_pass_utf8( $text ) {
10791079
* There's an established valid numeric character reference. Trim its leading zeros
10801080
* unless it's a single quote, in which case there's an exception for legacy `'`.
10811081
*/
1082-
$zero = 39 === $code_point ? '0' : '';
1083-
$hex_prefix = 16 === $numeric_base ? 'x' : '';
1082+
$zero = ( 10 === $numeric_base && 39 === $code_point ) ? '0' : '';
1083+
$hex_prefix = 16 === $numeric_base ? $text[ $at + 2 ] : '';
10841084
$digits = strtoupper( substr( $text, $digits_at, $digit_count ) );
10851085
$output .= '&#' . $hex_prefix . $zero . $digits . ';';
10861086
$at = $num_at + 1;

tests/phpunit/tests/formatting/escAttr.php

Lines changed: 63 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,4 +31,67 @@ public function test_esc_attr_amp() {
3131
$out = esc_attr( 'foo & bar &baz;  ' );
3232
$this->assertSame( 'foo & bar &baz;  ', $out );
3333
}
34+
35+
/**
36+
* Verifies the conversion of various kinds of decimal numeric references.
37+
*
38+
* @ticket {TICKET_NUMBER}
39+
*
40+
* @dataProvider data_decimal_numeric_references
41+
*
42+
* @param string $input Attribute value with decimal character references.
43+
* @param string $output How WordPress is expected to transform the attribute value.
44+
*/
45+
public function test_converts_decimal_numeric_references( $input, $output ) {
46+
$this->assertSame( $output, esc_attr( $input ), 'Failed to properly convert input.' );
47+
}
48+
49+
/**
50+
* Data provider.
51+
*
52+
* @return array[].
53+
*/
54+
public function data_decimal_numeric_references() {
55+
return array(
56+
'Basic decimal' => array( '‣', '‣' ),
57+
'Control character' => array( '', '' ),
58+
'Leading zeros' => array( 'A', 'A' ),
59+
'Leading zeros on \'' => array( ''', ''' ),
60+
'Leading zero on \'' => array( ''', ''' ),
61+
'Surrogate half' => array( '�', '�' ),
62+
'Code point too high' => array( '�', '�' ),
63+
);
64+
}
65+
66+
/**
67+
* Verifies the conversion of various kinds of hexadecimal numeric references.
68+
*
69+
* @ticket {TICKET_NUMBER}
70+
*
71+
* @dataProvider data_hexadecimal_numeric_references
72+
*
73+
* @param string $input Attribute value with hexadecimal character references.
74+
* @param string $output How WordPress is expected to transform the attribute value.
75+
*/
76+
public function test_converts_hexadecimal_numeric_references( $input, $output ) {
77+
$this->assertSame( $output, esc_attr( $input ), 'Failed to properly convert input.' );
78+
}
79+
80+
/**
81+
* Data provider.
82+
*
83+
* @return array[].
84+
*/
85+
public function data_hexadecimal_numeric_references() {
86+
return array(
87+
'Basic lower hex' => array( '‣', '‣' ),
88+
'Basic upper hex' => array( '‣', '‣' ),
89+
'Control character' => array( '', '' ),
90+
'Leading zeros' => array( 'e', 'e' ),
91+
'Leading zeros on \'' => array( ''', ''' ),
92+
'Leading zero on \'' => array( ''', ''' ),
93+
'Surrogate half' => array( '�', '�' ),
94+
'Code point too high' => array( '', '' ),
95+
);
96+
}
3497
}

0 commit comments

Comments
 (0)