Skip to content

Commit

Permalink
reddit, test: even more of the comments link format is optional
Browse files Browse the repository at this point in the history
Reddit will accept /r/subreddit/comments/id, /comments/id, or even just
/id... The variations never end.
  • Loading branch information
dgw committed Nov 29, 2021
1 parent b1fed88 commit 2bad1e1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion sopel/modules/reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@
subreddit_url = r'%s/r/([\w-]+)/?$' % domain
post_or_comment_url = (
domain +
r'/r/\S+?/comments/(?P<submission>[\w-]+)'
r'(?:/r/\S+?)?/comments/(?P<submission>[\w-]+)'
r'(?:/?(?:[\w%]+/(?P<comment>[\w-]+))?)'
)
short_post_url = r'https?://(redd\.it|reddit\.com)/(?P<submission>[\w-]+)/?$'
Expand Down
9 changes: 6 additions & 3 deletions test/modules/test_modules_reddit.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,14 @@ def bot(botfactory, configfactory):
'https://reddit.com/r/subname/',
'https://www.reddit.com/r/subname',
'https://www.reddit.com/r/subname/',
'https://reddit.com/comments/123456',
'https://reddit.com/comments/123456/',
'https://www.reddit.com/comments/123456',
'https://www.reddit.com/comments/123456/',
'https://reddit.com/r/subname/comments/123456',
'https://reddit.com/r/subname/comments/123456/',
'https://www.reddit.com/comments/123456?param=value',
'https://www.reddit.com/comments/123456/?param=value',
'https://reddit.com/r/subname/comments/123456?param=value',
'https://reddit.com/r/subname/comments/123456/?param=value',
'https://www.reddit.com/r/subname/comments/123456',
Expand All @@ -54,9 +60,6 @@ def bot(botfactory, configfactory):
'https://reddit.com/r/subname/?param=value',
'https://www.reddit.com/r/subname?param=value',
'https://www.reddit.com/r/subname/?param=value',
# "shortlink" style allegedly seen in the wild, but not currently recognized
'https://reddit.com/comments/123456',
'https://reddit.com/comments/123456/',
)


Expand Down

0 comments on commit 2bad1e1

Please sign in to comment.