From e5345aa59d6573abb39b50285b63aafcddd9f13b Mon Sep 17 00:00:00 2001 From: Miikka Heikkinen Date: Thu, 4 Nov 2010 09:47:08 +0200 Subject: Make qmake to pass all UTF-8 characters unchanged through parser. QMakeProject::parse() calls QString::simplified(), which assumes any byte 0xA0 in multibyte UTF-8 characters is a space character (0x00A0 is unicode character NBSP [non-breaking space]) and replaces those bytes with regular space, corrupting the UTF-8 string. Fixed by temporarily changing all 0xA0 bytes in parser input to another non-space character 0x01A0. This is safe replacement as qmake doesn't accept unicode .pro files, so there should never be actual NBSP or the replacement 0x01A0 characters in a valid .pro file. Note that there are a couple of more uses of QString::simplified() in qmake, but those do not deal with strings that need to be UTF-8 compatible as far as I can tell, so no need to touch them. Cherry picked to 4.7 branch from master branch as part of QTBUG-15068, original commit: 15a7626480b64d85992bed819fe6052e0c5c8fa9 Task-number: QTBUG-15068 Task-number: QTBUG-14357 Reviewed-by: Oswald Buddenhagen --- qmake/project.cpp | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/qmake/project.cpp b/qmake/project.cpp index 427bea3..fe08b7b 100644 --- a/qmake/project.cpp +++ b/qmake/project.cpp @@ -677,7 +677,23 @@ QMakeProject::reset() bool QMakeProject::parse(const QString &t, QMap &place, int numLines) { - QString s = t.simplified(); + // To preserve the integrity of any UTF-8 characters in .pro file, temporarily replace the + // non-breaking space (0xA0) characters with another non-space character, so that + // QString::simplified() call will not replace it with space. + // Note: There won't be any two byte characters in .pro files, so 0x10A0 should be a safe + // replacement character. + static QChar nbsp(0xA0); + static QChar nbspFix(0x01A0); + QString s; + if (t.indexOf(nbsp) != -1) { + s = t; + s.replace(nbsp, nbspFix); + s = s.simplified(); + s.replace(nbspFix, nbsp); + } else { + s = t.simplified(); + } + int hash_mark = s.indexOf("#"); if(hash_mark != -1) //good bye comments s = s.left(hash_mark); -- cgit v0.12