aboutsummaryrefslogtreecommitdiffstats
path: root/x11/kdelibs4/files/patch-kdelibs-kjs
blob: ca4456320ee9f8579c3e4f99b971a2e2490a7048 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
------------------------------------------------------------------------
r645387 | porten | 2007-03-22 15:01:13 +0100 (Thu, 22 Mar 2007) | 4 lines

substitute some of the invalid sequences with the standard replacement
char. this matches Mozilla but not IE which leaves them unchanged (or
throws an exception)

------------------------------------------------------------------------
--- kjs/function.cpp
+++ kjs/function.cpp
@@ -244,11 +244,15 @@ UString decodeURI(ExecState *exec, UStri
       }
 
       // UTF-8 transform
+      const unsigned long replacementChar = 0xFFFD;
       unsigned long V;
       if (n == 2) {
    unsigned long yyyyy = octets[0] & 0x1F;
    unsigned long zzzzzz = octets[1] & 0x3F;
    V = (yyyyy << 6) | zzzzzz;
+   // 2-byte sequence overlong for this value?
+   if (V < 0xFF)
+     V = replacementChar;
    C = UChar((unsigned short)V);
       }
       else if (n == 3) {
@@ -256,6 +260,11 @@ UString decodeURI(ExecState *exec, UStri
    unsigned long yyyyyy = octets[1] & 0x3F;
    unsigned long zzzzzz = octets[2] & 0x3F;
    V = (xxxx << 12) | (yyyyyy << 6) | zzzzzz;
+   // 3-byte sequence overlong for this value,
+   // an invalid value or UTF-16 surrogate?
+   if (V < 0x800 || V == 0xFFFE || V == 0xFFFF ||
+       (V >= 0xD800 && V <= 0xDFFF))
+     V = replacementChar;
    C = UChar((unsigned short)V);
       }
       else {