Commit 47164fc
committed
URL query percent encoding is incorrect
https://bugs.webkit.org/show_bug.cgi?id=306742
rdar://169566553
Reviewed by Anne van Kesteren.
We have used ucnv_setFallback(converter, true) for many, many years
for our ICU-based text decoding. However, when using ICU to encode
non-UTF8 text through a URL, we need to not use the fallback.
This matches the behavior of Chrome and Firefox, and Chromium has a
comment saying this matches Netscape behavior.
This behavior is odd but already implemented and specified in
https://url.spec.whatwg.org/#string-percent-encode-after-encoding
Chromium implemented this by using a class for the URL encoding,
ICUCharsetConverter which does not call ucnv_setFallback, and a
separate class for text encoding, and TextCodecIcu, which does call
ucnv_setFallback. I've already used an abstract interface for this
rare case, URLTextEncoding, in order to keep it down to one
implementation, so I keep that design and use ucnv_setFallback
to turn off fallback when using UnencodableHandling::URLEncodedEntities
for URL query encoding, then I use ucnv_setFallback to reset the state
of the encoder when I'm done with the operation.
Test: imported/w3c/web-platform-tests/url/resources/percent-encoding.window.html
* LayoutTests/imported/w3c/web-platform-tests/url/percent-encoding.window-expected.txt:
* LayoutTests/imported/w3c/web-platform-tests/url/resources/percent-encoding.json:
* Source/WebCore/PAL/pal/text/TextCodecICU.cpp:
(PAL::TextCodecICU::encode const):
Canonical link: https://commits.webkit.org/306768@main1 parent 717c6c0 commit 47164fc
File tree
3 files changed
+14
-0
lines changed- LayoutTests/imported/w3c/web-platform-tests/url
- resources
- Source/WebCore/PAL/pal/text
3 files changed
+14
-0
lines changedLines changed: 2 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
13 | 13 | | |
14 | 14 | | |
15 | 15 | | |
| 16 | + | |
| 17 | + | |
16 | 18 | | |
17 | 19 | | |
Lines changed: 7 additions & 0 deletions
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
39 | 39 | | |
40 | 40 | | |
41 | 41 | | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
42 | 49 | | |
43 | 50 | | |
44 | 51 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
305 | 305 | | |
306 | 306 | | |
307 | 307 | | |
| 308 | + | |
308 | 309 | | |
309 | 310 | | |
310 | 311 | | |
| |||
321 | 322 | | |
322 | 323 | | |
323 | 324 | | |
| 325 | + | |
| 326 | + | |
| 327 | + | |
| 328 | + | |
324 | 329 | | |
325 | 330 | | |
326 | 331 | | |
| |||
0 commit comments