Skip to content

Commit

Permalink
fix: Social link parsing approach changed (#33610)
Browse files Browse the repository at this point in the history
* fix: Social link parsing approach changed

* fix: fix tests

* fix: better approach
  • Loading branch information
Inferato authored Apr 10, 2024
1 parent 25eb223 commit a6bd0e2
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ def validate_social_link(self, social_platform, link):
('twitter', 'https://www.twiter.com/edX/', None, False),
('twitter', 'https://www.twitter.com/edX/123s', None, False),
('twitter', 'twitter.com/edX', 'https://www.twitter.com/edX', True),
('twitter', 'twitter.com/edX?foo=bar', 'https://www.twitter.com/edX', True),
('twitter', 'twitter.com/edX?foo=bar', 'https://www.twitter.com/edX?foo=bar', True),
('twitter', 'twitter.com/test.user', 'https://www.twitter.com/test.user', True),
('linkedin', 'www.linkedin.com/harryrein', None, False),
('linkedin', 'www.linkedin.com/in/harryrein-1234', 'https://www.linkedin.com/in/harryrein-1234', True),
Expand Down
6 changes: 1 addition & 5 deletions openedx/core/djangoapps/user_api/accounts/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import random
import re
import string
from urllib.parse import urlparse # pylint: disable=import-error

import waffle # lint-amnesty, pylint: disable=invalid-django-waffle-import
from completion.models import BlockCompletion
Expand Down Expand Up @@ -85,11 +84,8 @@ def _get_username_from_social_link(platform_name, new_social_link):
if not new_social_link:
return new_social_link

# Parse the social link as if it were a URL.
parse_result = urlparse(new_social_link)
url_domain_and_path = parse_result[1] + parse_result[2]
url_stub = re.escape(settings.SOCIAL_PLATFORMS[platform_name]['url_stub'])
username_match = re.search(r'(www\.)?' + url_stub + r'(?P<username>.*?)[/]?$', url_domain_and_path, re.IGNORECASE)
username_match = re.search(r'(www\.)?' + url_stub + r'(?P<username>.+?)(?:/)?$', new_social_link, re.IGNORECASE)
if username_match:
username = username_match.group('username')
else:
Expand Down

0 comments on commit a6bd0e2

Please sign in to comment.