Skip to content

Commit fba221d

Browse files
authored
Ensure the conference URL always has a scheme (#379)
* Ensure the conference URL always has a scheme * Clarify why the extra parsing logic is necessary
1 parent 9e9d9d2 commit fba221d

File tree

1 file changed

+14
-1
lines changed

1 file changed

+14
-1
lines changed

_conferences/__main__.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
import re
33
from datetime import datetime, time
44
from pathlib import Path
5+
from urllib.parse import urlparse
56

67
import yaml
78
from github import Auth, Github
@@ -45,6 +46,18 @@
4546
re.DOTALL,
4647
)
4748

49+
# Set a default value of None for when the url field isn't as expected
50+
valid_url = None
51+
52+
# Ensure the url field is not blank and the url matches the regex
53+
if url_match is not None and url_match[1].strip() != "":
54+
# Parse the url and see if a scheme (`https`) is included in it
55+
# If not, then prepend `https` to the url from the issue body
56+
# This guards against the website thinking the passed in url is another page on https://blackpythondevs.com/
57+
parsed_url = urlparse(url_match[1])
58+
if "http" not in parsed_url.scheme.casefold():
59+
valid_url = f"https://{url_match[1]}"
60+
4861
if dates_match:
4962
conferenceDates = dates_match[1]
5063
# Parse the end date of the conference
@@ -54,7 +67,7 @@
5467
if endDate >= today:
5568
conference = {
5669
"name": name_match[1],
57-
"url": url_match[1],
70+
"url": valid_url,
5871
"dates": dates_match[1],
5972
"type": type_match[1],
6073
"location": location_match[1],

0 commit comments

Comments
 (0)