]> git.lyx.org Git - lyx.git/commitdiff
Display URL-encoded chars decoded in display path
authorJuergen Spitzmueller <spitz@lyx.org>
Sat, 23 Mar 2019 14:15:08 +0000 (15:15 +0100)
committerJuergen Spitzmueller <spitz@lyx.org>
Sat, 23 Mar 2019 14:15:08 +0000 (15:15 +0100)
src/frontends/qt4/GuiLyXFiles.cpp
src/frontends/qt4/GuiWorkArea.cpp
src/support/filetools.cpp
src/support/lstrings.cpp
src/support/lstrings.h

index 89623b77c3cbad2024536e181e6f09b15c7b35a9..880a742891da7d533e18ea50b683b8ca267877d9 100644 (file)
@@ -42,8 +42,8 @@ namespace {
 
 QString const guiString(QString in)
 {
-       // recode specially encoded chars in file names
-       return in.replace('_', ' ').replace("%26", "&").replace("%28", "(").replace("%29", ")");
+       // recode specially encoded chars in file names (URL encoding and underbar)
+       return QString(QByteArray::fromPercentEncoding(in.toUtf8())).replace('_', ' ');
 }
 
 } // namespace anon
index 7842958c735531cce9e4a95f8f0a65df13c54b69..cb3f71f9f079da6772f56158eb70ab03414c74c3 100644 (file)
@@ -1871,9 +1871,12 @@ public:
        DisplayPath(int tab, FileName const & filename)
                : tab_(tab)
        {
+               // Recode URL encoded chars via fromPercentEncoding()
                filename_ = (filename.extension() == "lyx") ?
-                       toqstr(filename.onlyFileNameWithoutExt())
-                       : toqstr(filename.onlyFileName());
+                       QString(QByteArray::fromPercentEncoding(
+                                       toqstr(filename.onlyFileNameWithoutExt()).toUtf8()))
+                       : QString(QByteArray::fromPercentEncoding(
+                                         toqstr(filename.onlyFileName()).toUtf8()));
                postfix_ = toqstr(filename.absoluteFilePath()).
                        split("/", QString::SkipEmptyParts);
                postfix_.pop_back();
index 7a2739bda1cc60bce104c908674452274aa3e346..e8119959fd66314a7e6a1c842fb6a086fb161ca8 100644 (file)
@@ -931,6 +931,9 @@ docstring const makeDisplayPath(string const & path, unsigned int threshold)
 {
        string str = path;
 
+       // Recode URL encoded chars.
+       str = from_percent_encoding(str);
+
        // If file is from LyXDir, display it as if it were relative.
        string const system = package().system_support().absFileName();
        if (prefixIs(str, system) && str != system)
index 3195762a4a280fd9d0cdc5133bd21f180f098705..84757b3085775f24a1d48543887b1329d4873e98 100644 (file)
@@ -1459,6 +1459,13 @@ docstring to_percent_encoding(docstring const & in, docstring const & ex)
 }
 
 
+string from_percent_encoding(string const & in)
+{
+       QByteArray input = toqstr(in).toUtf8();
+       return fromqstr(QString(QByteArray::fromPercentEncoding(input)));
+}
+
+
 docstring bformat(docstring const & fmt, int arg1)
 {
        LATTEST(contains(fmt, from_ascii("%1$d")));
index 1ff9dfd811683711cf9c3daa4ba0cbc0b42cf5a7..dde06e545419cd49d0ae0b7910d3deaa1e84264d 100644 (file)
@@ -357,6 +357,8 @@ std::string formatFPNumber(double);
 /// \p ex defines a string of characters that are excluded from the transformation
 docstring to_percent_encoding(docstring const & in, docstring const & ex = docstring());
 
+/// Returns a string decoded from an URI/URL-style percent-encoded string \p in.
+std::string from_percent_encoding(std::string const & in);
 
 docstring bformat(docstring const & fmt, int arg1);
 docstring bformat(docstring const & fmt, long arg1);