Skip to content

Fix/wms provider url decoding#62446

Merged
troopa81 merged 14 commits into
qgis:masterfrom
benoitdm-oslandia:fix/wms-provider-url-decoding
Nov 20, 2025
Merged

Fix/wms provider url decoding#62446
troopa81 merged 14 commits into
qgis:masterfrom
benoitdm-oslandia:fix/wms-provider-url-decoding

Conversation

@benoitdm-oslandia

Copy link
Copy Markdown
Collaborator

This closes #62310 and reopens #59144 plus some changes:

  • rebase from master
  • remove merge and revert commits
  • squash some commits
  • fix qgshttpheaders accordingly
  • add tests

closes #31192
closes #59143

cc @cioddi

Comment thread src/providers/wms/qgswmsprovider.cpp Outdated
@github-actions

github-actions Bot commented Jun 27, 2025

Copy link
Copy Markdown
Contributor

🍎 MacOS Qt6 builds

Download MacOS Qt6 builds of this PR for testing.
This installer is not signed, control+click > open the app to avoid the warning
(Built from commit 0d10f88)

🪟 Windows builds

Download Windows builds of this PR for testing.
Debug symbols for this build are available here.
(Built from commit 7e14472)

🪟 Windows Qt6 builds

Download Windows Qt6 builds of this PR for testing.
(Built from commit 0d10f88)

@github-actions github-actions Bot added this to the 3.46.0 milestone Jun 27, 2025
@benoitdm-oslandia benoitdm-oslandia self-assigned this Jul 1, 2025
@benoitdm-oslandia benoitdm-oslandia force-pushed the fix/wms-provider-url-decoding branch from 04ed226 to 739c6ec Compare July 1, 2025 11:17
@github-actions

Copy link
Copy Markdown
Contributor

The QGIS project highly values your contribution and would love to see this work merged! Unfortunately this PR has not had any activity in the last 14 days and is being automatically marked as "stale". If you think this pull request should be merged, please check

  • that all unit tests are passing

  • that all comments by reviewers have been addressed

  • that there is enough information for reviewers, in particular

    • link to any issues which this pull request fixes

    • add a description of workflows which this pull request fixes

    • add screenshots if applicable

  • that you have written unit tests where possible
    In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this pull request.
    If there is no further activity on this pull request, it will be closed in a week.

@github-actions github-actions Bot added the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Jul 16, 2025
@github-actions

Copy link
Copy Markdown
Contributor

While we hate to see this happen, this PR has been automatically closed because it has not had any activity in the last 21 days. If this pull request should be reconsidered, please follow the guidelines in the previous comment and reopen this pull request. Or, if you have any further questions, just ask! We love to help, and if there's anything the QGIS project can do to help push this PR forward please let us know how we can assist.

@github-actions github-actions Bot closed this Jul 23, 2025
@github-actions github-actions Bot removed the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Jul 23, 2025
@benoitdm-oslandia

Copy link
Copy Markdown
Collaborator Author

ping @troopa81, for review please!

@benoitdm-oslandia benoitdm-oslandia force-pushed the fix/wms-provider-url-decoding branch from 739c6ec to 1f2418d Compare July 30, 2025 13:25
@benoitdm-oslandia

Copy link
Copy Markdown
Collaborator Author

rebase from master

@3nids 3nids modified the milestones: 3.46.0, 4.0.0 Aug 1, 2025
@nyalldawson

Copy link
Copy Markdown
Collaborator

@benoitdm-oslandia does this change break stable api? I.e would existing code relying on the old behavior (such as constructing a wms layer from a hard coded source string) be impacted?

@github-actions

Copy link
Copy Markdown
Contributor

The QGIS project highly values your contribution and would love to see this work merged! Unfortunately this PR has not had any activity in the last 14 days and is being automatically marked as "stale". If you think this pull request should be merged, please check

  • that all unit tests are passing

  • that all comments by reviewers have been addressed

  • that there is enough information for reviewers, in particular

    • link to any issues which this pull request fixes

    • add a description of workflows which this pull request fixes

    • add screenshots if applicable

  • that you have written unit tests where possible
    In case you should have any uncertainty, please leave a comment and we will be happy to help you proceed with this pull request.
    If there is no further activity on this pull request, it will be closed in a week.

@github-actions github-actions Bot added the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Aug 19, 2025
@benoitdm-oslandia

Copy link
Copy Markdown
Collaborator Author

@benoitdm-oslandia does this change break stable api? I.e would existing code relying on the old behavior (such as constructing a wms layer from a hard coded source string) be impacted?

Sorry, what do you mean by hard coded? Can you provide a more precise usecase?

@github-actions github-actions Bot removed the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Aug 20, 2025
@kannes

kannes commented Aug 21, 2025

Copy link
Copy Markdown
Contributor

I am 99% sure Nyall means URI strings that users might have saved and that are required to keep working. E. g. if you have a custom basemap plugin that contains a list of services defined by URIs. Will those keep working fine or is there potential breakage?

@benoitdm-oslandia

Copy link
Copy Markdown
Collaborator Author

@nyalldawson @kannes I am 99% sure the plugins will keep working fine :) The fixes brought by this PR are mainly to improve the support of url decoding and to homogeneize the uri encoding. But maybe some usecases are not tested!

@nyalldawson

nyalldawson commented Aug 22, 2025

Copy link
Copy Markdown
Collaborator

@benoitdm-oslandia

but there's changes in tests like this:

image

and

image

That to me suggests that the previous hardcoded URIs are now broken, which would also affect plugins and scripts =>this is an api break.

@benoitdm-oslandia

Copy link
Copy Markdown
Collaborator Author

@nyalldawson I add some usecases in the test you mentioned and, from what I understood, it does not generate an API break.

@cioddi

cioddi commented Aug 29, 2025

Copy link
Copy Markdown
Contributor

I will try to explain the situation.

The current state is, parts of the source configuration is stored in the form of URL parameters. When the value of an individual key is retrieved, it is always decoded using QUrl::PrettyDecoded (https://doc.qt.io/qt-6/qurlquery.html#queryItems).

The change in die PR will make sure values that are added to the QUrlQuery object are fully URL encoded (https://doc.qt.io/qt-6/qurl.html#ComponentFormattingOption-enum) first. The retrieval function QUrlQuery::queryItems parameter was changed from the default QUrl::PrettyDecoded (from the Qt docs: "The component is returned in a "pretty form", with most percent-encoded characters decoded. The exact behavior of PrettyDecoded varies from component to component and may also change from Qt release to Qt release. This is the default.") to the reliable and predictable QUrl::FullyDecoded. This ensures that the exact value that was passed in a data source URL parameter can be retrieved from it again.

Why is this important?
Especially in more complex QGIS server deployments we often rely on the non WMS spec "map" URL parameter to specify information about which project or configuration is supposed to be processed with the request. The value often contains characters that collide with URL parameter reserved characters such as ?, &, = so the value must be URL encoded (which is fine).

Now if we consume the WMS provided by QGIS server using a QGIS client the only way to make this work with current versions of QGIS is to double URL encode the values passed to the map parameter. That way at the time QGIS assembles the URL for an HTTP request to the server the value becomes single URL encoded because that is the way QUrlQuery::queryItems works by default.

(The server acts only as an example here, but could be any data source that expects a URL parameter value the QGIS client would send in a URL encoded form)

What this PR will break

This will break projects that are currently using the double URL encoded value workaround in a datasource. In those cases the source configuration must be updated. After updating the double URL encoded URL parameter values to single URL encoded ones, those will start working again. (this must be added to breaking changes)

General thoughts

Using a URL-parameter String is probably not the best way to store/handle the configuration of a data source and maybe in the future it should be considered to switch to something that better fits the requirements (like XML that is already used anyway for project files). This PR makes sure though that we can work with the current URL parameter config in a reliable way.

Comment thread src/core/qgsdatasourceuri.cpp Outdated
Comment thread src/core/qgsmaplayer.cpp Outdated
const QString url = uriComponents[QStringLiteral( "url" )].toString();
QUrl decodedUri = QUrl::fromPercentEncoding( uriComponents[QStringLiteral( "url" )].toString().toLocal8Bit() );
if ( decodedUri.scheme().isEmpty() && decodedUri.path().startsWith( "http" ) )
// url can be encoded twice and needs another % decoding

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't get why they could be encoded twice ? or even once ? Here we get the non-encoded url, the one store in the layer. We encode only in QgsDataSourceUri::encodedUri(), no?

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After discussion, we should display the url as it was entered by the user. If he enters an already encoded URL, we display it encoded.

Copy link
Copy Markdown
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In fact, as it is saved encoded, it had to be decoded at least once!

Comment thread tests/src/core/testqgsvectortilelayer.cpp Outdated
@troopa81

troopa81 commented Nov 3, 2025

Copy link
Copy Markdown
Contributor

One problem I have encountered. When examining the source properties the URL displayed in the "information"-tab is not URL-decoded and does not work if I click on the link. If I right click->open URL I get this something like this: "Cannot show URL Failed to load URL https%3A%2F%2Fsgx.geodatenzentrum.de%2Fwms_basemapde%3FVersion=1.3.0."

But why would you want to enter an already percent encoded URL. I understand that we can have a MAP or postgres url subpart that could be encoded but IMHO encoding the whole URL makes no sense. In the case of postgres/MAP subpart, we should let it encoded because it would be invalid otherwise.

@github-actions github-actions Bot removed the stale Uh oh! Seems this work is abandoned, and the PR is about to close. label Nov 3, 2025
@troopa81 troopa81 reopened this Nov 3, 2025
@benoitdm-oslandia benoitdm-oslandia force-pushed the fix/wms-provider-url-decoding branch from 8d6daab to bd10a30 Compare November 4, 2025 15:39
@benoitdm-oslandia

Copy link
Copy Markdown
Collaborator Author

@troopa81 I have found a bug with the vectortile provider while adjusting the tests. It does not seem a nice fix to me :(

@benoitdm-oslandia benoitdm-oslandia force-pushed the fix/wms-provider-url-decoding branch from bd10a30 to de40da8 Compare November 17, 2025 15:14
…roperly decoded when retrieved, preventing any potential loss of information.
URl-encoded in URL-parameter values characters will be URL-decoded on retrieval.
…ded in tests/src/providers/testqgswmsprovider.cpp
@benoitdm-oslandia benoitdm-oslandia force-pushed the fix/wms-provider-url-decoding branch from 2dbebd1 to 25ef836 Compare November 19, 2025 08:33

@troopa81 troopa81 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

After long discussion and thorough reviewing, I'm OK with the PR in this actual state.

Thank you @benoitdm-oslandia

cioddi and others added 11 commits November 19, 2025 16:45
… QgsDataSourceUri param setter and getter functions to URI serialization QgsDataSourceUri::encodedUri()
…sDataSourceUri strings in QgsDataSourceUri::setEncodedUri
add decoding step before adding the "url" value to QgsDataSourceUri in TestQgsIdentify::identifyVectorTile(), as QgsDataSourceUri now reliably returns the values that were provided.

adjust tests to QgsDataSourceUri full value URL-encoding

fix test tests/src/core/testqgshttpheaders.cpp

fix test tests/src/core/testqgssensorthingsconnection.cpp

fix test tests/src/core/testqgstiledsceneconnection.cpp

fix test tests/src/core/testqgsvectortileconnection.cpp

fix test tests/src/python/test_qgsvectortile.py

fix test tests/src/server/wms/test_qgsserver_wms_parameters.cpp

fix tests tests/src/core/testqgshttpheaders.cpp

fix most tests in tests/src/core/testqgsvectortilelayer.cpp
@benoitdm-oslandia benoitdm-oslandia force-pushed the fix/wms-provider-url-decoding branch from 25ef836 to 0d10f88 Compare November 19, 2025 15:45
@troopa81 troopa81 merged commit 1ba5886 into qgis:master Nov 20, 2025
33 checks passed
@ViperMiniQ ViperMiniQ mentioned this pull request Jan 22, 2026
@ViperMiniQ

Copy link
Copy Markdown
Contributor

Hi @benoitdm-oslandia,
this broke the loading of SLPK files from local files.
Can you please have a look at #64543?

Also, some of the reported paths in the metadata look weird now and I don't think it was an intended behavior.

Prior to this PR:
Screenshot_20260122_202951

After:
Screenshot_20260122_202919

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

inconsistent URL encoding/decoding with WMS sources Add WMS server fails with QGIS Server with Postgresql project

7 participants