Skip to content

Commit

Permalink
Remove redundant relativeToAbsoluteUri call
Browse files Browse the repository at this point in the history
- The b9c1c2c commit introduced redundant absoluteToRelativeUri AND
  relativeToAbsoluteUri calls. First one was removed earlier, stopping
  the #60100 issue. Remove the latter for completeness too.
- Minor indentation fix
  • Loading branch information
vsydorov committed Jan 10, 2025
1 parent 4c12aa2 commit 87a02d1
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 22 deletions.
5 changes: 2 additions & 3 deletions src/core/qgsmaplayer.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -565,17 +565,16 @@ bool QgsMapLayer::readLayerXml( const QDomElement &layerElement, QgsReadWriteCon
mnl = layerElement.namedItem( QStringLiteral( "datasource" ) );
mne = mnl.toElement();
const QString dataSourceRaw = mne.text();
mDataSource = provider.isEmpty() ? dataSourceRaw : QgsProviderRegistry::instance()->relativeToAbsoluteUri( provider, dataSourceRaw, context );

// if the layer needs authentication, ensure the master password is set
const thread_local QRegularExpression rx( "authcfg=([a-z]|[A-Z]|[0-9]){7}" );
if ( rx.match( mDataSource ).hasMatch()
if ( rx.match( dataSourceRaw ).hasMatch()
&& !QgsApplication::authManager()->setMasterPassword( true ) )
{
return false;
}

mDataSource = decodedSource( mDataSource, provider, context );
mDataSource = decodedSource( dataSourceRaw, provider, context );

// Set the CRS from project file, asking the user if necessary.
// Make it the saved CRS to have WMS layer projected correctly.
Expand Down
37 changes: 18 additions & 19 deletions tests/src/core/testqgsproject.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1107,25 +1107,24 @@ void TestQgsProject::testAsynchronousLayerLoading()
void TestQgsProject::regression60100()
{
/*
* Regression test for QGIS issue #60100 (https://github.com/qgis/QGIS/issues/60100)
* This test ensures that when saving a QGIS project with relative paths,
* the correct layer datasource is preserved, even when the current working
* directory (CWD) contains a file with the same name as the layer datasource.
*
* Previous behavior:
* - If a file with the same name as a layer datasource existed in the CWD,
* the layer path in the saved project would point to the file in the CWD,
* rather than the intended file in the project directory (PROJDIR).
*
* Test steps:
* 1. Create a temporary directory structure with two subfolders: WORKDIR and PROJDIR.
* 2. Copy a `points.geojson` file to both WORKDIR and PROJDIR.
* 3. Create a new QGIS project in PROJDIR and add the `points.geojson` file from PROJDIR as a layer.
* 4. Change the working directory to WORKDIR and save the project.
* 5. Verify that the saved project references the correct datasource (`./points.geojson` in PROJDIR)
* and does not erroneously reference the file in WORKDIR.
*/

* Regression test for QGIS issue #60100 (https://github.com/qgis/QGIS/issues/60100)
* This test ensures that when saving a QGIS project with relative paths,
* the correct layer datasource is preserved, even when the current working
* directory (CWD) contains a file with the same name as the layer datasource.
*
* Previous behavior:
* - If a file with the same name as a layer datasource existed in the CWD,
* the layer path in the saved project would point to the file in the CWD,
* rather than the intended file in the project directory (PROJDIR).
*
* Test steps:
* 1. Create a temporary directory structure with two subfolders: WORKDIR and PROJDIR.
* 2. Copy a `points.geojson` file to both WORKDIR and PROJDIR.
* 3. Create a new QGIS project in PROJDIR and add the `points.geojson` file from PROJDIR as a layer.
* 4. Change the working directory to WORKDIR and save the project.
* 5. Verify that the saved project references the correct datasource (`./points.geojson` in PROJDIR)
* and does not erroneously reference the file in WORKDIR.
*/
// Create directory structure with 2 subfolders
const QTemporaryDir baseDir;
const QDir base( baseDir.path() );
Expand Down

0 comments on commit 87a02d1

Please sign in to comment.