Commit 153f076
committed
HTML API: Respect document compat mode when handling CSS class names.
The HTML API has been behaving as if CSS class name selectors matched class names in an ASCII case-insensitive manner. This is only true if the document in question is set to quirks mode. Unfortunately most documents processed will be set to no-quirks mode, meaning that some CSS behaviors have been matching incorrectly when provided with case variants of class names.
In this patch, the CSS methods have been audited and updated to adhere to the rules governing ASCII case sensitivity when matching classes. This includes `add_class()`, `remove_class()`, `has_class()`, and `class_list()`. Now, it is assumed that a document is in no-quirks mode unless a full HTML parser infers quirks mode, and these methods will treat class names in a byte-for-byte manner. Otherwise, when a document is in quirks mode, the methods will compare the provided class names against existing class names for the tag in an ASCII case insensitive way, while `class_list()` will return a lower-cased version of the existing class names.
The lower-casing in `class_list()` is performed for consistency, since it's possible that multiple case variants of the same comparable class name exists on a tag in the input HTML.
Developed in WordPress/wordpress-develop#7169
Discussed in https://core.trac.wordpress.org/ticket/61531
Props dmsnell, jonsurrell.
See #61531.
Built from https://develop.svn.wordpress.org/trunk@58985
git-svn-id: https://core.svn.wordpress.org/trunk@58381 1a063a9b-81f0-0310-95a4-ce76da25c4cd1 parent fe51709 commit 153f076
4 files changed
Lines changed: 150 additions & 78 deletions
File tree
- wp-includes
- html-api
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
299 | 299 | | |
300 | 300 | | |
301 | 301 | | |
302 | | - | |
303 | | - | |
304 | | - | |
305 | | - | |
306 | | - | |
307 | | - | |
308 | | - | |
309 | | - | |
310 | | - | |
311 | | - | |
312 | | - | |
313 | | - | |
314 | | - | |
315 | | - | |
316 | | - | |
317 | | - | |
318 | | - | |
319 | | - | |
320 | | - | |
321 | | - | |
322 | | - | |
323 | | - | |
324 | | - | |
325 | | - | |
326 | | - | |
327 | 302 | | |
328 | 303 | | |
329 | 304 | | |
| |||
381 | 356 | | |
382 | 357 | | |
383 | 358 | | |
384 | | - | |
385 | | - | |
386 | | - | |
387 | | - | |
388 | | - | |
389 | | - | |
390 | | - | |
391 | | - | |
392 | | - | |
393 | | - | |
394 | | - | |
395 | | - | |
396 | | - | |
397 | | - | |
398 | | - | |
399 | | - | |
400 | | - | |
401 | | - | |
402 | | - | |
403 | | - | |
404 | | - | |
405 | | - | |
406 | | - | |
407 | | - | |
408 | 359 | | |
409 | 360 | | |
410 | 361 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
1080 | 1080 | | |
1081 | 1081 | | |
1082 | 1082 | | |
1083 | | - | |
| 1083 | + | |
1084 | 1084 | | |
1085 | 1085 | | |
1086 | 1086 | | |
| |||
1095 | 1095 | | |
1096 | 1096 | | |
1097 | 1097 | | |
1098 | | - | |
| 1098 | + | |
1099 | 1099 | | |
1100 | 1100 | | |
1101 | 1101 | | |
| |||
2448 | 2448 | | |
2449 | 2449 | | |
2450 | 2450 | | |
2451 | | - | |
| 2451 | + | |
2452 | 2452 | | |
2453 | 2453 | | |
2454 | 2454 | | |
| |||
4938 | 4938 | | |
4939 | 4939 | | |
4940 | 4940 | | |
| 4941 | + | |
| 4942 | + | |
| 4943 | + | |
| 4944 | + | |
4941 | 4945 | | |
4942 | 4946 | | |
4943 | 4947 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
511 | 511 | | |
512 | 512 | | |
513 | 513 | | |
| 514 | + | |
| 515 | + | |
| 516 | + | |
| 517 | + | |
| 518 | + | |
| 519 | + | |
| 520 | + | |
| 521 | + | |
| 522 | + | |
| 523 | + | |
| 524 | + | |
| 525 | + | |
| 526 | + | |
| 527 | + | |
| 528 | + | |
| 529 | + | |
| 530 | + | |
| 531 | + | |
| 532 | + | |
| 533 | + | |
| 534 | + | |
| 535 | + | |
| 536 | + | |
| 537 | + | |
| 538 | + | |
| 539 | + | |
514 | 540 | | |
515 | 541 | | |
516 | 542 | | |
| |||
1155 | 1181 | | |
1156 | 1182 | | |
1157 | 1183 | | |
| 1184 | + | |
| 1185 | + | |
1158 | 1186 | | |
1159 | 1187 | | |
1160 | 1188 | | |
| |||
1169 | 1197 | | |
1170 | 1198 | | |
1171 | 1199 | | |
1172 | | - | |
1173 | | - | |
1174 | | - | |
1175 | | - | |
1176 | | - | |
1177 | | - | |
1178 | | - | |
| 1200 | + | |
| 1201 | + | |
| 1202 | + | |
| 1203 | + | |
| 1204 | + | |
1179 | 1205 | | |
1180 | 1206 | | |
1181 | 1207 | | |
| |||
1205 | 1231 | | |
1206 | 1232 | | |
1207 | 1233 | | |
1208 | | - | |
| 1234 | + | |
1209 | 1235 | | |
| 1236 | + | |
1210 | 1237 | | |
1211 | | - | |
| 1238 | + | |
| 1239 | + | |
| 1240 | + | |
| 1241 | + | |
1212 | 1242 | | |
1213 | 1243 | | |
1214 | 1244 | | |
| |||
2296 | 2326 | | |
2297 | 2327 | | |
2298 | 2328 | | |
| 2329 | + | |
| 2330 | + | |
| 2331 | + | |
| 2332 | + | |
| 2333 | + | |
| 2334 | + | |
| 2335 | + | |
| 2336 | + | |
| 2337 | + | |
| 2338 | + | |
| 2339 | + | |
| 2340 | + | |
| 2341 | + | |
| 2342 | + | |
| 2343 | + | |
| 2344 | + | |
| 2345 | + | |
2299 | 2346 | | |
2300 | 2347 | | |
2301 | 2348 | | |
| |||
2311 | 2358 | | |
2312 | 2359 | | |
2313 | 2360 | | |
2314 | | - | |
2315 | | - | |
2316 | | - | |
2317 | | - | |
2318 | | - | |
2319 | | - | |
2320 | | - | |
2321 | | - | |
| 2361 | + | |
| 2362 | + | |
| 2363 | + | |
2322 | 2364 | | |
2323 | | - | |
2324 | | - | |
2325 | | - | |
| 2365 | + | |
| 2366 | + | |
| 2367 | + | |
| 2368 | + | |
2326 | 2369 | | |
2327 | 2370 | | |
2328 | | - | |
2329 | | - | |
| 2371 | + | |
| 2372 | + | |
2330 | 2373 | | |
2331 | 2374 | | |
2332 | 2375 | | |
| 2376 | + | |
| 2377 | + | |
2333 | 2378 | | |
2334 | 2379 | | |
2335 | 2380 | | |
| |||
2350 | 2395 | | |
2351 | 2396 | | |
2352 | 2397 | | |
2353 | | - | |
| 2398 | + | |
| 2399 | + | |
2354 | 2400 | | |
2355 | 2401 | | |
2356 | 2402 | | |
| |||
3932 | 3978 | | |
3933 | 3979 | | |
3934 | 3980 | | |
3935 | | - | |
| 3981 | + | |
| 3982 | + | |
| 3983 | + | |
| 3984 | + | |
3936 | 3985 | | |
| 3986 | + | |
| 3987 | + | |
| 3988 | + | |
| 3989 | + | |
| 3990 | + | |
| 3991 | + | |
| 3992 | + | |
| 3993 | + | |
| 3994 | + | |
| 3995 | + | |
| 3996 | + | |
| 3997 | + | |
| 3998 | + | |
| 3999 | + | |
| 4000 | + | |
| 4001 | + | |
| 4002 | + | |
| 4003 | + | |
3937 | 4004 | | |
3938 | 4005 | | |
3939 | 4006 | | |
| |||
3953 | 4020 | | |
3954 | 4021 | | |
3955 | 4022 | | |
3956 | | - | |
| 4023 | + | |
3957 | 4024 | | |
| 4025 | + | |
| 4026 | + | |
| 4027 | + | |
| 4028 | + | |
| 4029 | + | |
| 4030 | + | |
| 4031 | + | |
| 4032 | + | |
| 4033 | + | |
| 4034 | + | |
| 4035 | + | |
| 4036 | + | |
| 4037 | + | |
| 4038 | + | |
| 4039 | + | |
| 4040 | + | |
| 4041 | + | |
| 4042 | + | |
3958 | 4043 | | |
3959 | 4044 | | |
| 4045 | + | |
3960 | 4046 | | |
3961 | 4047 | | |
3962 | 4048 | | |
| |||
4350 | 4436 | | |
4351 | 4437 | | |
4352 | 4438 | | |
| 4439 | + | |
| 4440 | + | |
| 4441 | + | |
| 4442 | + | |
| 4443 | + | |
| 4444 | + | |
| 4445 | + | |
| 4446 | + | |
| 4447 | + | |
| 4448 | + | |
| 4449 | + | |
| 4450 | + | |
| 4451 | + | |
| 4452 | + | |
| 4453 | + | |
| 4454 | + | |
| 4455 | + | |
| 4456 | + | |
| 4457 | + | |
| 4458 | + | |
| 4459 | + | |
| 4460 | + | |
| 4461 | + | |
| 4462 | + | |
| 4463 | + | |
| 4464 | + | |
| 4465 | + | |
| 4466 | + | |
| 4467 | + | |
| 4468 | + | |
| 4469 | + | |
4353 | 4470 | | |
4354 | 4471 | | |
4355 | 4472 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
16 | 16 | | |
17 | 17 | | |
18 | 18 | | |
19 | | - | |
| 19 | + | |
20 | 20 | | |
21 | 21 | | |
22 | 22 | | |
| |||
0 commit comments