Skip to content

Commit

Permalink
wikipedia: fix unreliable urlparse() usage
Browse files Browse the repository at this point in the history
  • Loading branch information
SnoopJ committed Nov 29, 2023
1 parent 7693af3 commit 4b4b118
Showing 1 changed file with 7 additions and 3 deletions.
10 changes: 7 additions & 3 deletions sopel/builtins/wikipedia.py
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,16 @@ def mw_image_description(server, image):
def mw_info(bot, trigger, match=None):
"""Retrieves and outputs a snippet of the linked page."""
server = match.group(1)
page_info = urlparse(match.group(2))
article = unquote(page_info.path)
page_info = urlparse(match.match.string)
# in Python 3.9+ this can be str.removeprefix() instead, but we're confident that
# "/wiki/" is at the start of the path anyway since it's part of the pattern
trim_offset = len("/wiki/")
article = unquote(page_info.path)[trim_offset:]
section = unquote(page_info.fragment)

if section:
if section.startswith('cite_note-'): # Don't bother trying to retrieve a snippet when cite-note is linked
if section.startswith('cite_note-'):
# Don't bother trying to retrieve a snippet when cite-note is linked
say_snippet(bot, trigger, server, article, show_url=False)
elif section.startswith('/media'):
# gh2316: media fragments are usually images; try to get an image description
Expand Down

0 comments on commit 4b4b118

Please sign in to comment.