Skip to content

Commit

Permalink
identify invalid URL vs. perfect URL
Browse files Browse the repository at this point in the history
plus HTTPS
  • Loading branch information
𝐢𝐁𝐮𝐠 ♦ committed Sep 28, 2018
1 parent 39d533e commit 6e46ed1
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 5 deletions.
6 changes: 4 additions & 2 deletions chatcommands.py
Expand Up @@ -1446,7 +1446,7 @@ def report_posts(urls, reported_by, reported_in=None, blacklist_by=None, operati
normalized_urls = []
for url in urls:
t = url_to_shortlink(url)
if t == url:
if not t:
normalized_urls.append("That does not look like a valid post URL.")
elif t not in normalized_urls:
normalized_urls.append(t)
Expand Down Expand Up @@ -1548,7 +1548,9 @@ def report_posts(urls, reported_by, reported_in=None, blacklist_by=None, operati

@command(str, str, privileged=True, whole_msg=True)
def feedback(msg, post_url, feedback):
post_url = url_to_shortlink(post_url)[5:]
post_url = url_to_shortlink(post_url)[6:]
if not post_url:
raise CmdException("No such feedback.")

for feedbacks in (TRUE_FEEDBACKS, FALSE_FEEDBACKS, NAA_FEEDBACKS):
if feedback in feedbacks:
Expand Down
6 changes: 3 additions & 3 deletions parsing.py
Expand Up @@ -219,15 +219,15 @@ def get_user_from_list_command(cmd): # for example, !!/addblu is a list command
def url_to_shortlink(url):
id_and_site = fetch_post_id_and_site_from_url(url)
if id_and_site is None:
return url
return None
if id_and_site[2] == "question":
return "http://{}/questions/{}".format(id_and_site[1], id_and_site[0])
return "https://{}/questions/{}".format(id_and_site[1], id_and_site[0])
# We're using "/questions" and not "/q" here because when the URL
# is made protocol-relative, /q would redirect to http even if the
# shortlink is https. Same for /a. But there we still use /a because
# there is no /answers or something like that.
else:
return "http://{}/a/{}".format(id_and_site[1], id_and_site[0])
return "https://{}/a/{}".format(id_and_site[1], id_and_site[0])


# noinspection PyMissingTypeHints
Expand Down

0 comments on commit 6e46ed1

Please sign in to comment.