Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix/wms provider url decoding #59144

Open
wants to merge 14 commits into
base: master
Choose a base branch
from

Conversation

cioddi
Copy link

@cioddi cioddi commented Oct 20, 2024

Fixes #59143 - inconsistent URL encoding/decoding with WMS sources

I will take a look at tests before marking this PR ready.
May take some time as I am currently working on a 12 year old notebook.

fixed reproduction (see #59143 for a description of the current behaviour)

  1. open QGIS and the request debug console
  2. add a WMS data source with the URL https://127.0.0.1/%26%3F%26%3F/?non_standard_param=%26%3F%26%3F%26%3F
  • in qgsnewhttpconnection.cpp (363) QUrl decodes some of the URL-encoded characters resulting in https://127.0.0.1/%26?%26?/
    QUrl url( txtUrl->text().trimmed() );
  • in qgsnewhttpconnection.cpp (381) the QUrl query is set to non_standard_param=%26%3F%26%3F%26%3F
    url.setQuery( query );
  • in qgsowsconnection.cpp (87) the QgsDataSourceUri param "url" is set to the original url https://127.0.0.1/%26%3F%26%3F/?non_standard_param=%26%3F%26%3F%26%3F resulting in the param value https%3A%2F%2F127.0.0.1%2F%2526%253F%2526%253F%2F%3Fnon_standard_param%3D%2526%253F%2526%253F%2526%253F
    mUri.setParam( QStringLiteral( "url" ), url );
  1. right click the new WMS data source and click refresh
  • in qgswmsdataitems.cpp (61) the QgsDataSourceUri is parsed. mUri has the value dpiMode=7&featureCount=10&tilePixelRatio=0&url=https%3A%2F%2F127.0.0.1%2F%2526%253F%2526%253F%2F%3Fnon_standard_param%3D%2526%253F%2526%253F%2526%253F. The whole url value is now URL-encoded making it now possible to retain the original URL.
    uri.setEncodedUri( mUri );
  1. the GetCapabilities request is made to https://127.0.0.1/%26%3F%26%3F/?non_standard_param=%26%3F%26%3F%26%3F&SERVICE=WMS&REQUEST=GetCapabilities
  • qgswmscapabilities.cpp (2559) QNetworkRequest request( url );

We should not decode an entire URL if it includes parameters, as special characters in the query string (like `&`, `=`) must remain URL-encoded to avoid breaking the structure of the request. Within the URL-parameter values must never be URL-decoded as it leads to a loss of information, this is also the case if only non reserved characters are decoded. There is no way to know whether those characters have been encoded in the first place.
…roperly decoded when retrieved, preventing any potential loss of information.
@github-actions github-actions bot added this to the 3.40.0 milestone Oct 20, 2024
Copy link

github-actions bot commented Oct 20, 2024

🪟 Windows builds

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

@nyalldawson nyalldawson added the Frozen Feature freeze - Do not merge! label Oct 20, 2024
@nyalldawson
Copy link
Collaborator

Tagging as frozen -- this should not be merged prior to 3.40, as there's too great a risk of regressions at this late stage in the release cycle

@cioddi
Copy link
Author

cioddi commented Oct 21, 2024

I agree, this needs to be done with care. So definitely not 3.40.

@elpaso I will see whether it can be done when URI is serialized.

… QgsDataSourceUri param setter and getter functions to URI serialization QgsDataSourceUri::encodedUri()
…sDataSourceUri strings in QgsDataSourceUri::setEncodedUri
…n TestQgsIdentify::identifyVectorTile(), as QgsDataSourceUri now reliably returns the values that were provided.
@cioddi
Copy link
Author

cioddi commented Oct 22, 2024

I set this "Ready for review" just to enable the GH actions tests but it seems like one of the maintainers has to approve them.

@cioddi cioddi marked this pull request as ready for review October 22, 2024 09:22
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Frozen Feature freeze - Do not merge!
Projects
None yet
Development

Successfully merging this pull request may close these issues.

inconsistent URL encoding/decoding with WMS sources
3 participants