summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlex Richardson <arichardson.kde@gmail.com>2015-08-14 15:54:33 (GMT)
committerAlex Richardson <arichardson.kde@gmail.com>2015-08-28 17:03:59 (GMT)
commitab700b245355a2d42f7fcea1e62923fb2e65b880 (patch)
tree94c479e282609abbf41d26cbde9093863fe2e9ea
parentc3decc55f7d8b8b1786eee7cd6d4372cb985d998 (diff)
Restore the URL parsing behaviour in from before the KF5 port
This fixes shelltest REVIEW: 124738
-rw-r--r--autotests/CMakeLists.txt2
-rw-r--r--autotests/shelltest.cpp32
-rw-r--r--shell/shellutils.cpp23
3 files changed, 43 insertions, 14 deletions
diff --git a/autotests/CMakeLists.txt b/autotests/CMakeLists.txt
index 96a8dce..4530c33 100644
--- a/autotests/CMakeLists.txt
+++ b/autotests/CMakeLists.txt
@@ -5,7 +5,7 @@ include_directories(${CMAKE_CURRENT_BINARY_DIR}/..)
ecm_add_test(shelltest.cpp ../shell/shellutils.cpp
TEST_NAME "shelltest"
- LINK_LIBRARIES Qt5::Test okularcore KF5::KDELibs4Support
+ LINK_LIBRARIES Qt5::Test okularcore
)
ecm_add_test(parttest.cpp
diff --git a/autotests/shelltest.cpp b/autotests/shelltest.cpp
index 0f750ae..6ac8fc1 100644
--- a/autotests/shelltest.cpp
+++ b/autotests/shelltest.cpp
@@ -9,18 +9,17 @@
#include <QtTest>
-#include <qdir.h>
-#include <kcmdlineargs.h>
-#include <kurl.h>
+#include <QDir>
+#include <QUrl>
#include "../shell/shellutils.h"
static const QUrl makeUrlFromCwd( const QString& u, const QString& ref = QString() )
{
- QUrl url( QUrl::fromLocalFile( QDir::currentPath() + '/' + u ));
+ QUrl url = QUrl::fromLocalFile( QDir::currentPath() + '/' + u) ;
if ( !ref.isEmpty() )
url.setFragment( ref );
- url.setPath(QDir::cleanPath(url.path()));
+ url.setPath(QDir::cleanPath( url.path() ) );
return url;
}
@@ -48,8 +47,6 @@ class ShellTest
void ShellTest::initTestCase()
{
qRegisterMetaType<QUrl>();
-
- KCmdLineArgs::setCwd( QDir::currentPath().toLocal8Bit() );
}
void ShellTest::testUrlArgs_data()
@@ -84,19 +81,32 @@ void ShellTest::testUrlArgs_data()
QTest::newRow( "http://kde.org/foo.pdf" )
<< "http://kde.org/foo.pdf"
<< true
- << makeUrlFromCwd( "http://kde.org/foo.pdf" );
+ << QUrl( "http://kde.org/foo.pdf" );
+ // make sure we don't have a fragment
+ QUrl hashInName( "http://kde.org" );
+ QVERIFY( hashInName.path().isEmpty() );
+ hashInName.setPath( "/foo#bar.pdf" );
+ QVERIFY( hashInName.fragment().isEmpty() );
QTest::newRow( "http://kde.org/foo#bar.pdf" )
<< "http://kde.org/foo#bar.pdf"
<< true
- << makeUrlFromCwd( "http://kde.org/foo#bar.pdf" );
+ << hashInName;
+ QUrl withAnchor( "http://kde.org/foo.pdf" );
+ withAnchor.setFragment( "anchor" );
QTest::newRow( "http://kde.org/foo.pdf#anchor" )
<< "http://kde.org/foo.pdf#anchor"
<< true
- << makeUrlFromCwd( "http://kde.org/foo.pdf", "anchor" );
+ << withAnchor;
QTest::newRow( "#207461" )
<< "http://homepages.inf.ed.ac.uk/mef/file%20with%20spaces.pdf"
<< true
<< QUrl( "http://homepages.inf.ed.ac.uk/mef/file%20with%20spaces.pdf" );
+ QUrl openOnPage3 = QUrl( "http://itzsimpl.info/lectures/CG/L2-transformations.pdf" );
+ openOnPage3.setFragment( "3" );
+ QTest::newRow( "RR124738" )
+ << "http://itzsimpl.info/lectures/CG/L2-transformations.pdf#3"
+ << true
+ << openOnPage3;
}
void ShellTest::testUrlArgs()
@@ -104,7 +114,7 @@ void ShellTest::testUrlArgs()
QFETCH( QString, arg );
QFETCH( bool, exists );
QFETCH( QUrl, resUrl );
-
+ qDebug() << "Expected url:" << resUrl << "path =" << resUrl.path() << "fragment =" << resUrl.fragment();
QUrl url = ShellUtils::urlFromArg( arg, exists ? fileExist_always_Func : fileExist_never_Func );
QCOMPARE( url, resUrl );
}
diff --git a/shell/shellutils.cpp b/shell/shellutils.cpp
index 57ba130..a1f4d19 100644
--- a/shell/shellutils.cpp
+++ b/shell/shellutils.cpp
@@ -39,7 +39,7 @@ QUrl urlFromArg( const QString& _arg, FileExistFunc exist_func, const QString& p
{
// ## TODO remove exist_func
#if QT_VERSION >= 0x050400
- QUrl url = QUrl::fromUserInput(_arg, QDir::currentPath());
+ QUrl url = QUrl::fromUserInput(_arg, QDir::currentPath(), QUrl::AssumeLocalFile);
#else
// Code from QUrl::fromUserInput(QString, QString)
QUrl url = QUrl::fromUserInput(_arg);
@@ -49,8 +49,27 @@ QUrl urlFromArg( const QString& _arg, FileExistFunc exist_func, const QString& p
if (fileInfo.exists())
url = QUrl::fromLocalFile(fileInfo.absoluteFilePath());
}
-
#endif
+ if ( url.isLocalFile() ) {
+ // make sure something like /tmp/foo#bar.pdf is treated as a path name (default)
+ // but something like /tmp/foo.pdf#bar is foo.pdf plus an anchor "bar"
+ const QString path = url.path();
+ int hashIndex = path.lastIndexOf( QLatin1Char ( '#' ) );
+ int lastDotIndex = path.lastIndexOf( QLatin1Char ( '.' ) );
+ // make sure that we don't change the path if .pdf comes after the #
+ if ( hashIndex != -1 && hashIndex > lastDotIndex) {
+ url.setPath( path.left( hashIndex ) );
+ url.setFragment( path.mid( hashIndex + 1 ) );
+ qDebug() << "Added fragment to url:" << url.path() << url.fragment();
+ }
+ } else if ( !url.fragment().isEmpty() ) {
+ // make sure something like http://example.org/foo#bar.pdf is treated as a path name
+ // but something like http://example.org/foo.pdf#bar is foo.pdf plus an anchor "bar"
+ if ( url.fragment().contains( QLatin1Char( '.' ) ) ) {
+ url.setPath( url.path() + '#' + url.fragment() );
+ url.setFragment( QString() );
+ }
+ }
if ( !pageArg.isEmpty() )
{
url.setFragment( pageArg );