-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathurlCleaner.py
26 lines (17 loc) · 1.05 KB
/
urlCleaner.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
import re
class UrlCleaner():
def clean(self, urlToClean):
if not urlToClean.startswith('http://') and not urlToClean.startswith('https://'):
raise ValueError('Bad protocol. It should start with "http://" or "https://"')
if urlToClean.startswith('http://localhost') or urlToClean.startswith('https://localhost'):
raise ValueError('Cannot refer to localhost')
if urlToClean.startswith('http://127.0.0.1') or urlToClean.startswith('https://127.0.0.1'):
raise ValueError('Cannot refer to localhost')
if urlToClean.startswith('http://192.168.') or urlToClean.startswith('https://192.168.'):
raise ValueError('Cannot refer to lan address')
if urlToClean.startswith('http://172.16.') or urlToClean.startswith('https://172.16.'):
raise ValueError('Cannot refer to lan address')
if urlToClean.startswith('http://valte.ch') or urlToClean.startswith('http://shorten-url.appspot.com'):
raise ValueError('Cannot refer to self address')
# Remove strange characters
return re.sub('[<>\"\']', '', urlToClean)