diff options
author | Simon Hausmann <simon.hausmann@nokia.com> | 2011-05-16 12:04:31 (GMT) |
---|---|---|
committer | Simon Hausmann <simon.hausmann@nokia.com> | 2011-05-16 12:04:31 (GMT) |
commit | 8e321cd869da7ff1cf0168da41aa0246b44867cc (patch) | |
tree | 9d20da8dfa2531fdff16036f9dad7a6ec122e608 /tests/auto/qtextcodec | |
parent | f5acce7e11fa7c6abf5cf5352ec750c1ac65dd29 (diff) | |
download | Qt-8e321cd869da7ff1cf0168da41aa0246b44867cc.zip Qt-8e321cd869da7ff1cf0168da41aa0246b44867cc.tar.gz Qt-8e321cd869da7ff1cf0168da41aa0246b44867cc.tar.bz2 |
Fix inconsistency between Qt and ICU in Shift-JIS codec with regards to ASCII range
Qt's Shift-JIS codec maps the characters 0x5c and 0x7e to unicode yen (0x5a)
and unicode overline (0x203e). ICU and (as it turns out) Symbian's native
Shift-JIS codec preserve 0x5c and 0x7e when converting to Unicode.
Qt's behaviour creates a problem when loading japanese web sites that are
encoded in Shift-JIS. When they reference external JavaScript files, those tend
to inherit the current page encoding (unless the character set is explicitly
specified). Consequently JavaScript tends to contain regular expressions (as a
built-in feature of the language), which in turn uses backslashes for escape
sequences. Therefore it is crucial that the encodings used to decode the script
preserve the ASCII range, i.e. do not convert 0x5c (ascii backslash) to
something else.
This patch corrects the behaviour of Qt's Shift-JIS codec to leave all
characters < 0x80 unaltered in the process of conversion to and from
Unicode.
Task: QTBUG-19335
Reviewed-by: Lars Knoll <lars.knoll@nokia.com>
Diffstat (limited to 'tests/auto/qtextcodec')
-rw-r--r-- | tests/auto/qtextcodec/tst_qtextcodec.cpp | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/tests/auto/qtextcodec/tst_qtextcodec.cpp b/tests/auto/qtextcodec/tst_qtextcodec.cpp index 43656c8..15ecc3b 100644 --- a/tests/auto/qtextcodec/tst_qtextcodec.cpp +++ b/tests/auto/qtextcodec/tst_qtextcodec.cpp @@ -106,6 +106,8 @@ private slots: void moreToFromUnicode_data(); void moreToFromUnicode(); + + void shiftJis(); }; void tst_QTextCodec::toUnicode_data() @@ -2236,6 +2238,19 @@ void tst_QTextCodec::moreToFromUnicode() QCOMPARE(testData, cStr); } +void tst_QTextCodec::shiftJis() +{ + QByteArray backslashTilde("\\~"); + QTextCodec* codec = QTextCodec::codecForName("shift_jis"); + QString string = codec->toUnicode(backslashTilde); + QCOMPARE(string.length(), 2); + QCOMPARE(string.at(0), QChar(QLatin1Char('\\'))); + QCOMPARE(string.at(1), QChar(QLatin1Char('~'))); + + QByteArray encoded = codec->fromUnicode(string); + QCOMPARE(encoded, backslashTilde); +} + struct DontCrashAtExit { ~DontCrashAtExit() { QTextCodec *c = QTextCodec::codecForName("utf8"); |