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

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

Any updates on this PR ?

@ericholscher
Copy link
Member

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

@ericholscher ericholscher added the Needed: tests Tests are required label Mar 5, 2018
@bansalnitish
Copy link
Contributor Author

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

@bansalnitish
Copy link
Contributor Author

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

@ericholscher
Copy link
Member

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

@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

Choose a reason for hiding this comment

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

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

Copy link
Contributor Author

Choose a reason for hiding this comment

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

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

Copy link
Member

@humitos humitos left a comment

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

I think the correct regex here is:

[\w@\.\+-]+

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

Copy link
Member

Choose a reason for hiding this comment

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

Copy link
Member

Choose a reason for hiding this comment

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

@humitos no need to -1 yourself haha


def test_profile_details_page(self):

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

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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

Choose a reason for hiding this comment

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

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

@humitos
Copy link
Member

humitos commented May 10, 2018

Merging, Thanks!

@humitos humitos removed the Needed: tests Tests are required label May 10, 2018
@humitos humitos merged commit 696a25f into readthedocs:master May 10, 2018
@bansalnitish bansalnitish deleted the fixUrl branch May 10, 2018 04:23
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.

5 participants