From kde-commits Thu Mar 22 13:59:20 2007 From: Harri Porten Date: Thu, 22 Mar 2007 13:59:20 +0000 To: kde-commits Subject: branches/KDE/3.5/kdelibs/kjs Message-Id: <1174572075.745032.4120.nullmailer () svn ! kde ! org> X-MARC-Message: https://marc.info/?l=kde-commits&m=117457196019699 SVN commit 645387 by porten: 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) M +9 -0 function.cpp --- branches/KDE/3.5/kdelibs/kjs/function.cpp #645386:645387 @@ -244,11 +244,15 @@ } // 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 @@ 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 {