]> git.lyx.org Git - features.git/commitdiff
Fixup 3dc54d4a: fix string encoding issues with Qt4
authorJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 20 Jun 2019 09:22:53 +0000 (11:22 +0200)
committerJean-Marc Lasgouttes <lasgouttes@lyx.org>
Thu, 18 Jun 2020 13:48:33 +0000 (15:48 +0200)
The culprit here is the constructor QString(QByteArray const &): in
Qt4, it would interpret the byte array as latin1, and in Qt5 as utf8.

Therefore it is safer to use explicitly QString::fromUtf8 instead of
this constructor.

Several places where additionally simplified, in order to avoid some
extra conversions.

src/frontends/qt4/GuiLyXFiles.cpp
src/frontends/qt4/GuiWorkArea.cpp
src/support/lstrings.cpp

index 98c43419fdc29c3e4cfcb5e2e4bbcb4aceb6d907..6a59e6eea31c7a4cf657ec0ca938be3c82bb25ac 100644 (file)
@@ -43,7 +43,7 @@ namespace {
 QString const guiString(QString in)
 {
        // recode specially encoded chars in file names (URL encoding and underbar)
-       return QString(QByteArray::fromPercentEncoding(in.toUtf8())).replace('_', ' ');
+       return QString::fromUtf8(QByteArray::fromPercentEncoding(in.toUtf8())).replace('_', ' ');
 }
 
 } // namespace anon
index 001056df72abb1bdd551b007ae039982d010c59a..7955731ad36ed06432efa1a5df93e56f8ff81840 100644 (file)
@@ -1872,11 +1872,9 @@ public:
                : tab_(tab)
        {
                // Recode URL encoded chars via fromPercentEncoding()
-               filename_ = (filename.extension() == "lyx") ?
-                       QString(QByteArray::fromPercentEncoding(
-                                       toqstr(filename.onlyFileNameWithoutExt()).toUtf8()))
-                       : QString(QByteArray::fromPercentEncoding(
-                                         toqstr(filename.onlyFileName()).toUtf8()));
+               string const fn = (filename.extension() == "lyx")
+                       ? filename.onlyFileNameWithoutExt() : filename.onlyFileName();
+               filename_ = QString::fromUtf8(QByteArray::fromPercentEncoding(fn.c_str()));
                postfix_ = toqstr(filename.absoluteFilePath()).
                        split("/", QString::SkipEmptyParts);
                postfix_.pop_back();
index 84757b3085775f24a1d48543887b1329d4873e98..68eabd9d2649c310ecf6324831e19dd324ecd2b0 100644 (file)
@@ -1453,16 +1453,15 @@ std::string formatFPNumber(double x)
 
 docstring to_percent_encoding(docstring const & in, docstring const & ex)
 {
-       QByteArray input = toqstr(in).toUtf8();
-       QByteArray excludes = toqstr(ex).toUtf8();
-       return qstring_to_ucs4(QString(input.toPercentEncoding(excludes)));
+       QByteArray input = to_utf8(in).c_str();
+       QByteArray excludes = to_utf8(ex).c_str();
+       return from_utf8(string(input.toPercentEncoding(excludes).data()));
 }
 
 
 string from_percent_encoding(string const & in)
 {
-       QByteArray input = toqstr(in).toUtf8();
-       return fromqstr(QString(QByteArray::fromPercentEncoding(input)));
+       return QByteArray::fromPercentEncoding(in.c_str()).data();
 }