Skip to content

Commit 74a4d30

Browse files
authored
Merge pull request #64 from santoru/fix/bare-domain-normalization
Prepend https:// to bare domain names in normalize()
2 parents 2657959 + 9cc2c14 commit 74a4d30

2 files changed

Lines changed: 8 additions & 1 deletion

File tree

shcheck/shcheck.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -189,7 +189,8 @@ def normalize(target):
189189
if (socket.inet_aton(target)):
190190
target = 'http://' + target
191191
except (ValueError, socket.error):
192-
pass
192+
if not target.startswith(('http://', 'https://')):
193+
target = 'https://' + target
193194
return target
194195

195196

tests/test_shcheck.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -113,6 +113,12 @@ def test_append_port_without_trailing_slash():
113113
def test_normalize_bare_ip_adds_http():
114114
assert shcheck.normalize('192.168.1.1') == 'http://192.168.1.1'
115115

116+
def test_normalize_bare_domain_adds_https():
117+
assert shcheck.normalize('github.com') == 'https://github.com'
118+
119+
def test_normalize_bare_domain_with_path_adds_https():
120+
assert shcheck.normalize('github.com/santoru/shcheck') == 'https://github.com/santoru/shcheck'
121+
116122
def test_normalize_https_url_unchanged():
117123
assert shcheck.normalize('https://example.com') == 'https://example.com'
118124

0 commit comments

Comments
 (0)