Skip to content
This repository has been archived by the owner on Aug 26, 2022. It is now read-only.

Commit

Permalink
fix bug 1306087 - changing stackoverflow profile link regex to accept…
Browse files Browse the repository at this point in the history
… two-letter region domains
  • Loading branch information
mveritym committed Dec 2, 2016
1 parent 669e93b commit c060d3b
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 1 deletion.
2 changes: 1 addition & 1 deletion kuma/users/models.py
Expand Up @@ -115,7 +115,7 @@ class User(AbstractUser):
'invalid',
),
'stackoverflow': validators.RegexValidator(
r'^https?://stackoverflow\.com/users/',
r'^https?://([a-z]{2}\.)?stackoverflow\.com/users/',
_('Enter a valid Stack Overflow URL.'),
'invalid',
),
Expand Down
26 changes: 26 additions & 0 deletions kuma/users/tests/test_models.py
@@ -1,5 +1,7 @@
import pytest

from django.core.exceptions import ValidationError

from kuma.core.tests import eq_, ok_
from kuma.wiki.tests import revision

Expand Down Expand Up @@ -49,6 +51,30 @@ def test_linkedin_urls(self):
new_user = self.user_model.objects.get(pk=user.pk)
eq_(url, new_user.linkedin_url)

def test_stackoverflow_urls(self):
"""Bug 1306087: Accept two-letter country-localized stackoverflow
domains but not meta.stackoverflow.com."""
user = self.user_model.objects.get(username='testuser')

valid_stackoverflow_urls = [
'https://stackoverflow.com/users/testuser',
'https://es.stackoverflow.com/users/testuser',
]

for valid_url in valid_stackoverflow_urls:
user.stackoverflow_url = valid_url
user.full_clean()

invalid_stackoverflow_urls = [
'https://1a.stackoverflow.com/users/testuser',
'https://meta.stackoverflow.com/users/testuser'
]

for invalid_url in invalid_stackoverflow_urls:
user.stackoverflow_url = invalid_url
with self.assertRaises(ValidationError):
user.full_clean()

def test_irc_nickname(self):
"""We've added IRC nickname as a profile field.
Make sure it shows up."""
Expand Down

0 comments on commit c060d3b

Please sign in to comment.