diff options
Diffstat (limited to 'src/corelib/codecs/qtextcodec.cpp')
-rw-r--r-- | src/corelib/codecs/qtextcodec.cpp | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/src/corelib/codecs/qtextcodec.cpp b/src/corelib/codecs/qtextcodec.cpp index 0e671518ef..511817677c 100644 --- a/src/corelib/codecs/qtextcodec.cpp +++ b/src/corelib/codecs/qtextcodec.cpp @@ -1043,28 +1043,30 @@ QString QTextDecoder::toUnicode(const QByteArray &ba) QTextCodec *QTextCodec::codecForHtml(const QByteArray &ba, QTextCodec *defaultCodec) { // determine charset - int pos; - QTextCodec *c = 0; - - c = QTextCodec::codecForUtfText(ba, c); + QTextCodec *c = QTextCodec::codecForUtfText(ba, 0); if (!c) { QByteArray header = ba.left(512).toLower(); - if ((pos = header.indexOf("http-equiv=")) != -1) { - if ((pos = header.lastIndexOf("meta ", pos)) != -1) { - pos = header.indexOf("charset=", pos) + int(strlen("charset=")); - if (pos != -1) { - int pos2 = header.indexOf('\"', pos+1); - QByteArray cs = header.mid(pos, pos2-pos); - // qDebug("found charset: %s", cs.data()); - c = QTextCodec::codecForName(cs); + int pos = header.indexOf("meta "); + if (pos != -1) { + pos = header.indexOf("charset=", pos); + if (pos != -1) { + pos += qstrlen("charset="); + + int pos2 = pos; + // The attribute can be closed with either """, "'", ">" or "/", + // none of which are valid charset characters. + while (++pos2 < header.size()) { + char ch = header.at(pos2); + if (ch == '\"' || ch == '\'' || ch == '>') { + c = QTextCodec::codecForName(header.mid(pos, pos2 - pos)); + return c ? c : defaultCodec; + } } } } } - if (!c) - c = defaultCodec; - return c; + return defaultCodec; } /*! |