Display URL-encoded chars decoded in display path

This commit is contained in:
Juergen Spitzmueller 2019-03-23 15:15:08 +01:00
parent b8842a1584
commit 3dc54d4aac
5 changed files with 19 additions and 4 deletions

View 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

View 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();

View 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)

View 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")));

View 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);