From 3dc54d4aac3c59c1ec898668f9b956802dc0427f Mon Sep 17 00:00:00 2001 From: Juergen Spitzmueller Date: Sat, 23 Mar 2019 15:15:08 +0100 Subject: [PATCH] Display URL-encoded chars decoded in display path --- src/frontends/qt4/GuiLyXFiles.cpp | 4 ++-- src/frontends/qt4/GuiWorkArea.cpp | 7 +++++-- src/support/filetools.cpp | 3 +++ src/support/lstrings.cpp | 7 +++++++ src/support/lstrings.h | 2 ++ 5 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/frontends/qt4/GuiLyXFiles.cpp b/src/frontends/qt4/GuiLyXFiles.cpp index 89623b77c3..880a742891 100644 --- a/src/frontends/qt4/GuiLyXFiles.cpp +++ b/src/frontends/qt4/GuiLyXFiles.cpp @@ -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 diff --git a/src/frontends/qt4/GuiWorkArea.cpp b/src/frontends/qt4/GuiWorkArea.cpp index 7842958c73..cb3f71f9f0 100644 --- a/src/frontends/qt4/GuiWorkArea.cpp +++ b/src/frontends/qt4/GuiWorkArea.cpp @@ -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(); diff --git a/src/support/filetools.cpp b/src/support/filetools.cpp index 7a2739bda1..e8119959fd 100644 --- a/src/support/filetools.cpp +++ b/src/support/filetools.cpp @@ -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) diff --git a/src/support/lstrings.cpp b/src/support/lstrings.cpp index 3195762a4a..84757b3085 100644 --- a/src/support/lstrings.cpp +++ b/src/support/lstrings.cpp @@ -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"))); diff --git a/src/support/lstrings.h b/src/support/lstrings.h index 1ff9dfd811..dde06e5454 100644 --- a/src/support/lstrings.h +++ b/src/support/lstrings.h @@ -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); -- 2.39.2