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

Convert an IRI path to URI before setting as NGINX header #5024

Merged
merged 1 commit into from
Jan 10, 2019

Conversation

humitos
Copy link
Member

@humitos humitos commented Dec 20, 2018

Filepath can contains non-ASCII characters, so we need to convert to a valid URI before setting it as X-Accel-Redirec NGINX header because only ASCII characters are supported.

References,

Closes https://github.com/rtfd/readthedocs-corporate/issues/409

NOTE: I didn't test this locally because I don't have the setup needed (gunicorn + nginx) properly configured. So, we will need to be careful when deploying this into production.

One example of what this fixes is,

In [1]: from django.utils.encoding import iri_to_uri                                                                                                                                          

In [2]: iri_to_uri('camión.html')                                                                                                                                                             
Out[2]: 'cami%C3%B3n.html'

@humitos humitos requested a review from a team December 20, 2018 16:09
@humitos
Copy link
Member Author

humitos commented Dec 26, 2018

Test in py2.7 failed because git doesn't recognize --prune-tags :/

@humitos humitos added this to the 2.9 milestone Dec 26, 2018
@stsewd
Copy link
Member

stsewd commented Dec 26, 2018

@humitos ^ wrong PR I guess? 😆

@humitos
Copy link
Member Author

humitos commented Dec 27, 2018

Nope. It was failing, but I re-triggered the test and it passed 🤷‍♂️

@agjohnson
Copy link
Contributor

Is it worth adding a test here? I assume we already have tests for the send file header that should pass, but if not, that would be good to verify before/after this patch.

@humitos humitos force-pushed the humitos/nginx/encode-iri-filepath branch from 6a17ec5 to 565ac55 Compare January 3, 2019 09:31
@humitos
Copy link
Member Author

humitos commented Jan 3, 2019

Is it worth adding a test here?

Yes.

I assume we already have tests for the send file header that should pass

We did have tests, but of course none of them tested that Unicode was supported. I forget 100% to add a test here 😞

I just pushed a test for this and it's working 😄

@humitos humitos force-pushed the humitos/nginx/encode-iri-filepath branch from 565ac55 to b8e2048 Compare January 7, 2019 09:47
Filepath can contains non-ASCII characters, so we need to convert to a
valid URI before setting it as X-Accel-Redirec NGINX header because
only ASCII characters are supported.

References,

* https://docs.djangoproject.com/en/1.11/ref/unicode/#uri-and-iri-handling
* benoitc/gunicorn#1448
@humitos humitos force-pushed the humitos/nginx/encode-iri-filepath branch from b8e2048 to adb5218 Compare January 7, 2019 10:08
Copy link
Member

@ericholscher ericholscher left a comment

Choose a reason for hiding this comment

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

Looks good. 👍

@ericholscher ericholscher merged commit c2391c0 into master Jan 10, 2019
@delete-merged-branch delete-merged-branch bot deleted the humitos/nginx/encode-iri-filepath branch January 10, 2019 15:11
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.

4 participants