From e957417b21f68cceeb8536fe60f880c40bb7a7d5 Mon Sep 17 00:00:00 2001 From: Andrea Iacovitti Date: Fri, 6 Mar 2015 23:30:14 +0100 Subject: [PATCH 4/4] Fix parsing single-quoted meta charset attribute. Ignore whitespaces after the quote. BUG: 322484 FIXED-IN: 4.14.7 --- kdecore/localization/kencodingdetector.cpp | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/kdecore/localization/kencodingdetector.cpp b/kdecore/localization/kencodingdetector.cpp index 1f20bec..13b4909 100644 --- a/kdecore/localization/kencodingdetector.cpp +++ b/kdecore/localization/kencodingdetector.cpp @@ -1031,6 +1031,7 @@ bool KEncodingDetector::analyze(const char *data, int len) //if ( *end == '\0' ) break; QByteArray str( ptr, (end-ptr)+1); str = str.toLower(); + const int strLength = str.length(); int pos=0; //if( (pos = str.find("http-equiv", pos)) == -1) break; //if( (pos = str.find("content-type", pos)) == -1) break; @@ -1045,19 +1046,22 @@ bool KEncodingDetector::analyze(const char *data, int len) ++pos; // skip whitespace before encoding itself - while (pos < (int)str.length() && str[pos] <= ' ') + while (pos < strLength && str[pos] <= ' ') ++pos; - // there may also be an opening quote, if this is a charset= and not - // a http-equiv. - if (pos < (int)str.length() && str[pos] == '"') + // there may also be an opening quote, if this is a charset= and not a http-equiv. + if (pos < strLength && (str[pos] == '"' || str[pos] == '\'')) ++pos; - if ( pos == (int)str.length()) + // skip whitespace + while (pos < strLength && str[pos] <= ' ') + ++pos; + + if ( pos == strLength) continue; int endpos = pos; - while( endpos < str.length() && + while( endpos < strLength && (str[endpos] != ' ' && str[endpos] != '"' && str[endpos] != '\'' && str[endpos] != ';' && str[endpos] != '>') ) ++endpos; -- 2.3.1