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
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion readthedocs/profiles/urls/public.py
Expand Up @@ -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

views.profile_detail,
{'template_name': 'profiles/public/profile_detail.html'},
name='profiles_profile_detail'),
Expand Down
27 changes: 27 additions & 0 deletions readthedocs/rtd_tests/tests/test_views.py
Expand Up @@ -241,3 +241,30 @@ def test_project_admins_can_delete_subprojects_that_they_are_not_admin_of(self):
'/dashboard/my-mainproject/subprojects/my-subproject/delete/')
self.assertEqual(response.status_code, 302)
self.assertTrue(self.subproject not in [r.child for r in self.project.subprojects.all()])

class URLResolution(TestCase):
def setUp(self):
self.user1 = new(User, username='foo+bar')
self.user1.set_password('test1')
self.user1.save()

self.user2 = new(User, username='abc+def@ghi.jkl')
self.user2.set_password('test2')
self.user2.save()

self.user3 = new(User, username='abc-def+ghi')
self.user3.set_password('test3')
self.user3.save()

self.client.login(username='foo+bar', password='test1')

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

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!

self.assertEqual(response.status_code, 200)

response = self.client.get('/profiles/abc+def@ghi.jkl/')
self.assertEqual(response.status_code, 200)

response = self.client.get('/profiles/abc-def+ghi/')
self.assertEqual(response.status_code, 200)