@@ -116,7 +116,7 @@ function wp_specialchars( $text, $quotes = 0 ) {
116116 return $ text ;
117117}
118118
119- function utf8_uri_encode ( $ utf8_string ) {
119+ function utf8_uri_encode ( $ utf8_string, $ length = 0 ) {
120120 $ unicode = '' ;
121121 $ values = array ();
122122 $ num_octets = 1 ;
@@ -126,21 +126,25 @@ function utf8_uri_encode( $utf8_string ) {
126126 $ value = ord ( $ utf8_string [ $ i ] );
127127
128128 if ( $ value < 128 ) {
129+ if ( $ length && ( strlen ($ unicode ) + 1 > $ length ) )
130+ break ;
129131 $ unicode .= chr ($ value );
130132 } else {
131133 if ( count ( $ values ) == 0 ) $ num_octets = ( $ value < 224 ) ? 2 : 3 ;
132134
133135 $ values [] = $ value ;
134136
137+ if ( $ length && ( (strlen ($ unicode ) + ($ num_octets * 3 )) > $ length ) )
138+ break ;
135139 if ( count ( $ values ) == $ num_octets ) {
136- if ($ num_octets == 3 ) {
137- $ unicode .= '% ' . dechex ($ values [0 ]) . '% ' . dechex ($ values [1 ]) . '% ' . dechex ($ values [2 ]);
138- } else {
139- $ unicode .= '% ' . dechex ($ values [0 ]) . '% ' . dechex ($ values [1 ]);
140- }
140+ if ($ num_octets == 3 ) {
141+ $ unicode .= '% ' . dechex ($ values [0 ]) . '% ' . dechex ($ values [1 ]) . '% ' . dechex ($ values [2 ]);
142+ } else {
143+ $ unicode .= '% ' . dechex ($ values [0 ]) . '% ' . dechex ($ values [1 ]);
144+ }
141145
142- $ values = array ();
143- $ num_octets = 1 ;
146+ $ values = array ();
147+ $ num_octets = 1 ;
144148 }
145149 }
146150 }
@@ -317,7 +321,7 @@ function sanitize_title_with_dashes($title) {
317321 if (function_exists ('mb_strtolower ' )) {
318322 $ title = mb_strtolower ($ title , 'UTF-8 ' );
319323 }
320- $ title = utf8_uri_encode ($ title );
324+ $ title = utf8_uri_encode ($ title, 200 );
321325 }
322326
323327 $ title = strtolower ($ title );
0 commit comments