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

Fixes incorrectly encoded url current url #6685

Merged
merged 2 commits into from
Sep 27, 2022

Conversation

EricSoroos
Copy link
Contributor

Fixes #6684

Proposed fixes:

  • url in question /%EF%AC%81?foo=bar&bz=%AC%81
  • This is a unicode character, which can't be decoded from
    ascii. Jinja templates will handle this if it's unicode, or if it's
    hex encoded ascii, but can't take a non-unicode string in python 2 and
    put this in a template.
  • The querystring was being quoted, which is incorrect, as:
    1. the special characters in the query string mean something
    2. The rest of the querystring is already quoted. This makes it
      double quoted, as seen in the datastore file
  • We don't want to unquote urls before putting them in the template
    anyway.
  • There was s further error passing this unicode path to the template
    resolution, where in posix path, it fails:
File '/usr/lib/ckan/default/lib/python2.7/posixpath.py', line 73 in join
  path += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 1: ordinal not in range(128)

The solution here is to make sure it's unicode passed into the
function.

Features:

  • includes tests covering changes
  • includes updated documentation
  • includes user-visible changes
  • includes API changes
  • includes bugfix for possible backport

Please [X] all the boxes above that apply

* url in question /%EF%AC%81?foo=bar&bz=%AC%81
* This is a unicode character, which can't be decoded from
ascii. Jinja templates will handle this if it's unicode, or if it's
hex encoded ascii, but can't take a non-unicode string in python 2 and
put this in a template.
* The querystring was being quoted, which is incorrect, as:
  1) the special characters in the query string mean something
  2) The rest of the querystring is already quoted. This makes it
  double quoted, as seen in the datastore file
* We don't want to unquote urls before putting them in the template
anyway.
* There was s further error passing this unicode path to the template
resolution, where in posix path, it fails:
```
File '/usr/lib/ckan/default/lib/python2.7/posixpath.py', line 73 in join
  path += '/' + b
UnicodeDecodeError: 'ascii' codec can't decode byte 0xef in position 1: ordinal not in range(128)
```
The solution here is to make sure it's unicode passed into the
function.
@EricSoroos EricSoroos changed the title Fixes a two errors when dealing with a encoded url. Fixes two errors when dealing with a encoded url. Feb 2, 2022
@EricSoroos EricSoroos changed the title Fixes two errors when dealing with a encoded url. Fixes incorrectly encoded url current url Feb 2, 2022
@amercader
Copy link
Member

Let's search usage of CKAN_CURRENT_URL on popular extensions and mention this on the release notes.
And patch 2.9 and master as well

Copy link
Member

@amercader amercader left a comment

Choose a reason for hiding this comment

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

This sounds good @EricSoroos but can you add the tiny suggestion to make the tests pass, and also submit the same patch for master and 2.9? Thanks

@@ -29,6 +29,10 @@ def view(self, url):
By default this controller aborts the request with a 404 (Not
Found)
"""
try:
url = unicode(url.encode('utf-8'))
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
url = unicode(url.encode('utf-8'))
url = unicode(url.encode(u'utf-8'))

@amercader
Copy link
Member

@EricSoroos do you want to have a look at this?

@wardi
Copy link
Contributor

wardi commented Sep 22, 2022

@amercader this looks good to me but is against the 2.8 branch. If this code doesn't exist on master anymore would we still want something similar for 2.9?

@amercader
Copy link
Member

@wardi yes, that's #6926 , right?

@amercader amercader merged commit 369412e into ckan:dev-v2.8 Sep 27, 2022
@amercader
Copy link
Member

@EricSoroos This needs to be fixed in master as well:

Can you send a PR against master with these fixes? Thanks

@EricSoroos
Copy link
Contributor Author

@amercader Will do.

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

Successfully merging this pull request may close these issues.

Helpers.current_url returns inconsistently quoted url, causing 500 errors.
3 participants