From d5dd8fce018ae7457205a5a9b18932eebd899f07 Mon Sep 17 00:00:00 2001 From: Pino Toscano Date: Thu, 8 Oct 2009 22:12:21 +0000 Subject: [PATCH] when we remove the file:/ from the argument, do the precent-encoding removal to avoid being percent-encoded more than needed based on a patch by Albert, slightly changed + unit test by me BUG: 207461 svn path=/trunk/KDE/kdegraphics/okular/; revision=1032944 --- shell/shell.cpp | 5 +++++ tests/shelltest.cpp | 13 +++++++++++++ 2 files changed, 18 insertions(+) diff --git a/shell/shell.cpp b/shell/shell.cpp index 9863877af..32091e2c8 100644 --- a/shell/shell.cpp +++ b/shell/shell.cpp @@ -58,7 +58,12 @@ Shell::Shell(KCmdLineArgs* args, int argIndex) if any. */ QString arg = m_args->arg(argIndex); + const QString origArg = arg; arg.replace(QRegExp("^file:/{1,3}"), "/"); + if (arg != origArg) + { + arg = QString::fromUtf8(QByteArray::fromPercentEncoding(arg.toUtf8())); + } KUrl url = KCmdLineArgs::makeURL(arg.toUtf8()); int sharpPos = -1; if (!url.isLocalFile() || !QFile::exists(url.toLocalFile())) diff --git a/tests/shelltest.cpp b/tests/shelltest.cpp index ccf789461..e16626677 100644 --- a/tests/shelltest.cpp +++ b/tests/shelltest.cpp @@ -70,6 +70,10 @@ void ShellTest::testUrlArgs_data() << "foo.pdf#anchor" << false << makeUrlFromCwd( "foo.pdf", "anchor" ); + QTest::newRow( "#207461" ) + << "file:///tmp/file%20with%20spaces.pdf" + << true + << KUrl( "file:///tmp/file%20with%20spaces.pdf" ); // non-local files QTest::newRow( "http://kde.org/foo.pdf" ) @@ -84,6 +88,10 @@ void ShellTest::testUrlArgs_data() << "http://kde.org/foo.pdf#anchor" << true << makeUrlFromCwd( "http://kde.org/foo.pdf", "anchor" ); + QTest::newRow( "#207461" ) + << "http://homepages.inf.ed.ac.uk/mef/file%20with%20spaces.pdf" + << true + << KUrl( "http://homepages.inf.ed.ac.uk/mef/file%20with%20spaces.pdf" ); } void ShellTest::testUrlArgs() @@ -93,7 +101,12 @@ void ShellTest::testUrlArgs() QFETCH( KUrl, resUrl ); // note: below is a snippet taken from the Shell ctor + const QString origArg = arg; arg.replace(QRegExp("^file:/{1,3}"), "/"); + if (arg != origArg) + { + arg = QString::fromUtf8(QByteArray::fromPercentEncoding(arg.toUtf8())); + } KUrl url = KCmdLineArgs::makeURL(arg.toUtf8()); int sharpPos = -1; if (!url.isLocalFile() || !exists)