Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Merge pull request #9273 from elpaso/bugfix-fix-path-resolver-urls
fix path resolver urls
  • Loading branch information
elpaso committed Feb 25, 2019
2 parents 29b952d + 84e903c commit a3e3742
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 6 deletions.
2 changes: 1 addition & 1 deletion python/core/auto_generated/qgsdefaultvalue.sip.in
Expand Up @@ -17,7 +17,7 @@ The QgsDefaultValue class provides a container for managing client
side default values for fields.

A QgsDefaultValue consists of an expression string that will be evaluated
on the client when a defeault field value needs to be generated.
on the client when a default field value needs to be generated.

Usual values for such an expression are

Expand Down
2 changes: 1 addition & 1 deletion src/core/qgsdefaultvalue.h
Expand Up @@ -30,7 +30,7 @@
* side default values for fields.
*
* A QgsDefaultValue consists of an expression string that will be evaluated
* on the client when a defeault field value needs to be generated.
* on the client when a default field value needs to be generated.
*
* Usual values for such an expression are
*
Expand Down
27 changes: 23 additions & 4 deletions src/core/qgspathresolver.cpp
Expand Up @@ -18,6 +18,7 @@
#include "qgis.h"

#include <QFileInfo>
#include <QUrl>


QgsPathResolver::QgsPathResolver( const QString &baseFileName )
Expand Down Expand Up @@ -163,9 +164,20 @@ QString QgsPathResolver::writePath( const QString &src ) const
return src;
}

// Strip "file://"
QFileInfo srcFileInfo( src.startsWith( QStringLiteral( "file://" ) ) ? src.mid( 7 ) : src );
QString srcPath = srcFileInfo.exists() ? srcFileInfo.canonicalFilePath() : src;
// Check if it is a publicSource uri and clean it
QUrl url { src };
QString srcPath { src };
QString urlQuery;

if ( url.isLocalFile( ) )
{
srcPath = url.path();
urlQuery = url.query();
}

QFileInfo srcFileInfo( srcPath );
if ( srcFileInfo.exists() )
srcPath = srcFileInfo.canonicalFilePath();

// if this is a VSIFILE, remove the VSI prefix and append to final result
QString vsiPrefix = qgsVsiPrefix( src );
Expand Down Expand Up @@ -233,5 +245,12 @@ QString QgsPathResolver::writePath( const QString &src ) const
srcElems.insert( 0, QStringLiteral( "." ) );
}

return vsiPrefix + srcElems.join( QStringLiteral( "/" ) );
// Append url query if any
QString returnPath { vsiPrefix + srcElems.join( QStringLiteral( "/" ) ) };
if ( ! urlQuery.isEmpty() )
{
returnPath.append( '?' );
returnPath.append( urlQuery );
}
return returnPath;
}
21 changes: 21 additions & 0 deletions tests/src/core/testqgsproject.cpp
Expand Up @@ -42,6 +42,7 @@ class TestQgsProject : public QObject
void variablesChanged();
void testLayerFlags();
void testLocalFiles();
void testLocalUrlFiles();
};

void TestQgsProject::init()
Expand Down Expand Up @@ -406,6 +407,26 @@ void TestQgsProject::testLocalFiles()

}

void TestQgsProject::testLocalUrlFiles()
{
QTemporaryFile f;
QVERIFY( f.open() );
f.close();
QgsProject prj;
QFileInfo info( f.fileName() );
prj.setFileName( f.fileName() );
prj.write();
QString shpPath = info.dir().path() + '/' + info.baseName() + ".shp";
QString extraStuff {"?someVar=someValue&someOtherVar=someOtherValue" };
QString layerPath = "file://" + shpPath + extraStuff;
QFile f2( shpPath );
QVERIFY( f2.open( QFile::ReadWrite ) );
f2.close();
QgsPathResolver resolver( f.fileName( ) );
QCOMPARE( resolver.writePath( layerPath ), QString( "./" + info.baseName() + ".shp" + extraStuff ) ) ;

}


QGSTEST_MAIN( TestQgsProject )
#include "testqgsproject.moc"

0 comments on commit a3e3742

Please sign in to comment.