| 146 | |
| 147 | /** |
| 148 | * @ticket 24661 |
| 149 | */ |
| 150 | public function test_remove_accents_mn_combining_marks() { |
| 151 | // Creates a string with all Mn nonspacing combining marks. |
| 152 | // Using Unicode 5.0.0 to be compatible with PHP 5.2.4 (PCRE 7.2). |
| 153 | // Generated by "gen_remove_accents_ranges.php" from "http://www.unicode.org/Public/5.0.0/ucd/UnicodeData.txt". |
| 154 | $code_points = array_merge( |
| 155 | range( 0x300, 0x36f ) |
| 156 | , range( 0x483, 0x486 ) |
| 157 | , range( 0x591, 0x5bd ) |
| 158 | , array( 0x5bf ) |
| 159 | , range( 0x5c1, 0x5c2 ) |
| 160 | , range( 0x5c4, 0x5c5 ) |
| 161 | , array( 0x5c7 ) |
| 162 | , range( 0x610, 0x615 ) |
| 163 | , range( 0x64b, 0x65e ) |
| 164 | , array( 0x670 ) |
| 165 | , range( 0x6d6, 0x6dc ) |
| 166 | , range( 0x6df, 0x6e4 ) |
| 167 | , range( 0x6e7, 0x6e8 ) |
| 168 | , range( 0x6ea, 0x6ed ) |
| 169 | , array( 0x711 ) |
| 170 | , range( 0x730, 0x74a ) |
| 171 | , range( 0x7a6, 0x7b0 ) |
| 172 | , range( 0x7eb, 0x7f3 ) |
| 173 | , range( 0x901, 0x902 ) |
| 174 | , array( 0x93c ) |
| 175 | , range( 0x941, 0x948 ) |
| 176 | , array( 0x94d ) |
| 177 | , range( 0x951, 0x954 ) |
| 178 | , range( 0x962, 0x963 ) |
| 179 | , array( 0x981 ) |
| 180 | , array( 0x9bc ) |
| 181 | , range( 0x9c1, 0x9c4 ) |
| 182 | , array( 0x9cd ) |
| 183 | , range( 0x9e2, 0x9e3 ) |
| 184 | , range( 0xa01, 0xa02 ) |
| 185 | , array( 0xa3c ) |
| 186 | , range( 0xa41, 0xa42 ) |
| 187 | , range( 0xa47, 0xa48 ) |
| 188 | , range( 0xa4b, 0xa4d ) |
| 189 | , range( 0xa70, 0xa71 ) |
| 190 | , range( 0xa81, 0xa82 ) |
| 191 | , array( 0xabc ) |
| 192 | , range( 0xac1, 0xac5 ) |
| 193 | , range( 0xac7, 0xac8 ) |
| 194 | , array( 0xacd ) |
| 195 | , range( 0xae2, 0xae3 ) |
| 196 | , array( 0xb01 ) |
| 197 | , array( 0xb3c ) |
| 198 | , array( 0xb3f ) |
| 199 | , range( 0xb41, 0xb43 ) |
| 200 | , array( 0xb4d ) |
| 201 | , array( 0xb56 ) |
| 202 | , array( 0xb82 ) |
| 203 | , array( 0xbc0 ) |
| 204 | , array( 0xbcd ) |
| 205 | , range( 0xc3e, 0xc40 ) |
| 206 | , range( 0xc46, 0xc48 ) |
| 207 | , range( 0xc4a, 0xc4d ) |
| 208 | , range( 0xc55, 0xc56 ) |
| 209 | , array( 0xcbc ) |
| 210 | , array( 0xcbf ) |
| 211 | , array( 0xcc6 ) |
| 212 | , range( 0xccc, 0xccd ) |
| 213 | , range( 0xce2, 0xce3 ) |
| 214 | , range( 0xd41, 0xd43 ) |
| 215 | , array( 0xd4d ) |
| 216 | , array( 0xdca ) |
| 217 | , range( 0xdd2, 0xdd4 ) |
| 218 | , array( 0xdd6 ) |
| 219 | , array( 0xe31 ) |
| 220 | , range( 0xe34, 0xe3a ) |
| 221 | , range( 0xe47, 0xe4e ) |
| 222 | , array( 0xeb1 ) |
| 223 | , range( 0xeb4, 0xeb9 ) |
| 224 | , range( 0xebb, 0xebc ) |
| 225 | , range( 0xec8, 0xecd ) |
| 226 | , range( 0xf18, 0xf19 ) |
| 227 | , array( 0xf35 ) |
| 228 | , array( 0xf37 ) |
| 229 | , array( 0xf39 ) |
| 230 | , range( 0xf71, 0xf7e ) |
| 231 | , range( 0xf80, 0xf84 ) |
| 232 | , range( 0xf86, 0xf87 ) |
| 233 | , range( 0xf90, 0xf97 ) |
| 234 | , range( 0xf99, 0xfbc ) |
| 235 | , array( 0xfc6 ) |
| 236 | , range( 0x102d, 0x1030 ) |
| 237 | , array( 0x1032 ) |
| 238 | , range( 0x1036, 0x1037 ) |
| 239 | , array( 0x1039 ) |
| 240 | , range( 0x1058, 0x1059 ) |
| 241 | , array( 0x135f ) |
| 242 | , range( 0x1712, 0x1714 ) |
| 243 | , range( 0x1732, 0x1734 ) |
| 244 | , range( 0x1752, 0x1753 ) |
| 245 | , range( 0x1772, 0x1773 ) |
| 246 | , range( 0x17b7, 0x17bd ) |
| 247 | , array( 0x17c6 ) |
| 248 | , range( 0x17c9, 0x17d3 ) |
| 249 | , array( 0x17dd ) |
| 250 | , range( 0x180b, 0x180d ) |
| 251 | , array( 0x18a9 ) |
| 252 | , range( 0x1920, 0x1922 ) |
| 253 | , range( 0x1927, 0x1928 ) |
| 254 | , array( 0x1932 ) |
| 255 | , range( 0x1939, 0x193b ) |
| 256 | , range( 0x1a17, 0x1a18 ) |
| 257 | , range( 0x1b00, 0x1b03 ) |
| 258 | , array( 0x1b34 ) |
| 259 | , range( 0x1b36, 0x1b3a ) |
| 260 | , array( 0x1b3c ) |
| 261 | , array( 0x1b42 ) |
| 262 | , range( 0x1b6b, 0x1b73 ) |
| 263 | , range( 0x1dc0, 0x1dca ) |
| 264 | , range( 0x1dfe, 0x1dff ) |
| 265 | , range( 0x20d0, 0x20dc ) |
| 266 | , array( 0x20e1 ) |
| 267 | , range( 0x20e5, 0x20ef ) |
| 268 | , range( 0x302a, 0x302d ) // NOTE: U+302E & U+302F recategorized as Mc in Unicode 6.1.0 |
| 269 | , range( 0x3099, 0x309a ) |
| 270 | , array( 0xa806 ) |
| 271 | , array( 0xa80b ) |
| 272 | , range( 0xa825, 0xa826 ) |
| 273 | , array( 0xfb1e ) |
| 274 | , range( 0xfe00, 0xfe0f ) |
| 275 | , range( 0xfe20, 0xfe23 ) |
| 276 | , range( 0x10a01, 0x10a03 ) |
| 277 | , range( 0x10a05, 0x10a06 ) |
| 278 | , range( 0x10a0c, 0x10a0f ) |
| 279 | , range( 0x10a38, 0x10a3a ) |
| 280 | , array( 0x10a3f ) |
| 281 | , range( 0x1d167, 0x1d169 ) |
| 282 | , range( 0x1d17b, 0x1d182 ) |
| 283 | , range( 0x1d185, 0x1d18b ) |
| 284 | , range( 0x1d1aa, 0x1d1ad ) |
| 285 | , range( 0x1d242, 0x1d244 ) |
| 286 | , range( 0xe0100, 0xe01ef ) |
| 287 | ); // 878 code points |
| 288 | $combining_marks = 'a'; // Only if follow Latin character. |
| 289 | foreach ( $code_points as $c ) { |
| 290 | if ( $c < 0x800 ) { |
| 291 | $combining_marks .= chr( 0xc0 | $c >> 6 ) . chr( 0x80 | $c & 0x3f ); |
| 292 | } elseif ( $c < 0x10000 ) { |
| 293 | $combining_marks .= chr( 0xe0 | $c >> 12 ) . chr( 0x80 | $c >> 6 & 0x3f ) . chr( 0x80 | $c & 0x3f ); |
| 294 | } else { |
| 295 | $combining_marks .= chr( 0xf0 | $c >> 18 ) . chr( 0x80 | $c >> 12 & 0x3f ) . chr( 0x80 | $c >> 6 & 0x3f ) . chr( 0x80 | $c & 0x3f ); |
| 296 | } |
| 297 | } |
| 298 | // Performs the test: all the characters should be removed. |
| 299 | $this->assertSame( 'a', remove_accents( $combining_marks ) ); |
| 300 | if ( _wp_can_use_pcre_ucp() ) { // If UCP available. |
| 301 | // Test single-byte replace also. |
| 302 | _wp_can_use_pcre_ucp( false ); |
| 303 | $this->assertSame( 'a', remove_accents( $combining_marks ) ); |
| 304 | _wp_can_use_pcre_ucp( 'reset' ); |
| 305 | } |
| 306 | } |
| 307 | |
| 308 | /** |
| 309 | * @ticket 24661 |
| 310 | * @dataProvider data_remove_accents_combining |
| 311 | */ |
| 312 | function test_remove_accents_combining( $input, $output ) { |
| 313 | $this->assertSame( $output, remove_accents( $input ) ); |
| 314 | } |
| 315 | |
| 316 | function data_remove_accents_combining() { |
| 317 | return array( |
| 318 | // Test a collection of filenames that could have problems. |
| 319 | array( |
| 320 | "Capture d’e\xcc\x81cran 2013-02-20 a\xcc\x80 23.36.06.png", // NOTE: apostrophe is U+2019 |
| 321 | //"Capture d'ecran 2013-02-20 a 23.36.06.png", // NOTE: apostrophe should go to U+0029 |
| 322 | "Capture d’ecran 2013-02-20 a 23.36.06.png", |
| 323 | ), |
| 324 | array( |
| 325 | "Buttermo\xcc\x88deli.jpg", |
| 326 | "Buttermodeli.jpg", |
| 327 | ), |
| 328 | array( |
| 329 | "Mu\xcc\x88nsterl.Mai13a.jpg", |
| 330 | "Munsterl.Mai13a.jpg", |
| 331 | ), |
| 332 | |
| 333 | array( |
| 334 | 'Cáo nâu lanh lẹ nhảy qua người lười biếng. Do bạch kim rất quý, sẽ để lắp vô xương', |
| 335 | "Cao nau lanh le nhay qua nguoi luoi bieng. Do bach kim rat quy, se de lap vo xuong", |
| 336 | ), |
| 337 | array( |
| 338 | 'Příliš žluťoučký kůň úpěl ďábelské kódy. Pójdźże, kiń tę chmurność w głąb flaszy! Päťtýždňové vĺčatá nervózne štekajú na môjho ďatľa v tŕní.', |
| 339 | "Prilis zlutoucky kun upel dabelske kody. Pojdzze, kin te chmurnosc w glab flaszy! Pattyzdnove vlcata nervozne stekaju na mojho datla v trni.", |
| 340 | ), |
| 341 | array( |
| 342 | "Les naïfs ægithales hâtifs pondant à noël où il gèle sont sûrs d'être déçus en voyant leurs drôles d'œufs abîmés.", |
| 343 | "Les naifs aegithales hatifs pondant a noel ou il gele sont surs d'etre decus en voyant leurs droles d'oeufs abimes.", |
| 344 | ), |
| 345 | array( |
| 346 | 'a᷄ (a + combining macron-acute). +⃟ (plus with enclosing diamond). a︠e︡ (ae with a combining ligature)', |
| 347 | "a (a + combining macron-acute). +⃟ (plus with enclosing diamond). ae (ae with a combining ligature)", // NOTE: Not doing "Me" enclosing combining marks. |
| 348 | ), |
| 349 | |
| 350 | // From UTF-8 Sampler http://www.columbia.edu/~fdc/utf8/ |
| 351 | array( |
| 352 | // NOTE: U+200C ZERO WIDTH NON-JOINER not dealt with. |
| 353 | "Im finſteren Jagdſchloß am offenen Felsquellwaſſer patzte der affig-flatterhafte kauzig-höf\xe2\x80\x8cliche Bäcker über ſeinem verſifften kniffligen C-Xylophon.", |
| 354 | "Im finsteren Jagdschlos am offenen Felsquellwasser patzte der affig-flatterhafte kauzig-hof\xe2\x80\x8cliche Backer uber seinem versifften kniffligen C-Xylophon.", |
| 355 | ), |
| 356 | ); |
| 357 | } |