commit 3dc54d4aac3c59c1ec898668f9b956802dc0427f
Author: Juergen Spitzmueller <[email protected]>
Date: Sat Mar 23 15:15:08 2019 +0100
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 89623b7..880a742 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 7842958..cb3f71f 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 7a2739b..e811995 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 3195762..84757b3 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 1ff9dfd..dde06e5 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);