Skip to content

Commit

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

* feat: fix tests

* fix: tests

---------

Co-authored-by: Edward Zarecor <[email protected]>
  • Loading branch information
Inferato and e0d authored Apr 10, 2024
1 parent bf82569 commit 14777af
Show file tree
Hide file tree
Showing 2 changed files with 3 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
7 changes: 2 additions & 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,9 @@ 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 14777af

Please sign in to comment.