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 #2953 - Url resolved with special characters #3725

Merged
merged 3 commits into from May 10, 2018

Conversation

@bansalnitish
Copy link
Contributor

@bansalnitish bansalnitish commented Mar 3, 2018

This PR Fixes #2953. I have added the + character to the username set. Rest all characters letters , numbers, - and _ were already doing fine with the URL.

@bansalnitish
Copy link
Contributor Author

@bansalnitish bansalnitish commented Mar 4, 2018

Any updates on this PR ?

@ericholscher
Copy link
Member

@ericholscher ericholscher commented Mar 5, 2018

Thanks for the patch! This could use a test confirming that it does indeed work for projects with +'s. Similar to this: https://github.com/rtfd/readthedocs.org/blob/master/readthedocs/rtd_tests/tests/test_views.py#L115-L124

@bansalnitish
Copy link
Contributor Author

@bansalnitish bansalnitish commented Mar 6, 2018

Thanks for the review @ericholscher! I will add a test for this!

@bansalnitish
Copy link
Contributor Author

@bansalnitish bansalnitish commented Mar 6, 2018

@ericholscher Can you please guide about where these tests should be added?

@RichardLitt RichardLitt requested a review from ericholscher Mar 7, 2018
@ericholscher
Copy link
Member

@ericholscher ericholscher commented Mar 8, 2018

I linked the tests file above: https://github.com/rtfd/readthedocs.org/blob/master/readthedocs/rtd_tests/tests/test_views.py#L115-L124

You could also test the regex itself, outside of a view, and just confirm that it's matching what we expect.

@bansalnitish
Copy link
Contributor Author

@bansalnitish bansalnitish commented Mar 8, 2018

@ericholscher I have added the tests!


def test_project_details_resolve(self):
self.project.users.add(self.user)
response = self.client.get('/projects/my-mainproject/')
Copy link
Member

@stsewd stsewd Mar 8, 2018

I think this should test for the user profile /profiles/{user}/

Copy link
Contributor Author

@bansalnitish bansalnitish Mar 8, 2018

I have fixed that as well as added some new users for testing!

Copy link
Member

@humitos humitos left a comment

Thanks for your contribution!

This solves #3890

@@ -7,7 +7,7 @@


urlpatterns = [
url(r'^(?P<username>[\w@.-]+)/$',
url(r'^(?P<username>[+\w@.-]+)/$',
Copy link
Member

@humitos humitos Apr 4, 2018

I think the correct regex here is:

[\w@\.\+-]+

which follows the same as the django validation field from the username.

Copy link
Member

@stsewd stsewd Apr 4, 2018

@humitos no need to -1 yourself haha


def test_profile_details_page(self):

response = self.client.get('/profiles/foo+bar/')
Copy link
Member

@humitos humitos Apr 4, 2018

Instead of creating these users and accessing the page itself, isn't it better to use the resolver and check that it matches?

Copy link
Contributor Author

@bansalnitish bansalnitish Apr 13, 2018

Hi @humitos, Sorry for the delay on this. I was busy with class tests in my college.
Can you please elaborate on this as I am a bit confused about how to proceed.

Copy link
Member

@humitos humitos Apr 17, 2018

Sorry, I meant the reverse function from django:

In [1]: from django.core.urlresolvers import reverse

In [3]: reverse('profiles_profile_detail', kwargs={'username': 'foo+bar'})
Out[3]: '/profiles/foobar/'

and check the URL returned with assertEqual.

Copy link
Contributor Author

@bansalnitish bansalnitish Apr 17, 2018

Thanks for the explanation @humitos, I have made the changes!

@humitos
Copy link
Member

@humitos humitos commented May 10, 2018

Merging, Thanks!

@humitos humitos merged commit 696a25f into readthedocs:master May 10, 2018
1 check passed
@bansalnitish bansalnitish deleted the fixUrl branch May 10, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked issues

Successfully merging this pull request may close these issues.

None yet

5 participants