Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
go
Commits
5fab9c55
Commit
5fab9c55
authored
Feb 25, 2017
by
Grady Moran
Browse files
Now only prohibit 300 errors or links that start/end at go
(Closes
#108
)
parent
328ec7c2
Pipeline
#959
passed with stage
in 1 minute and 19 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
go/go/forms.py
View file @
5fab9c55
...
...
@@ -32,10 +32,15 @@ class URLForm(forms.ModelForm):
# note it WILL permit links that have go in an intermediary stage... such as bit.ly -> go -> not go.
try
:
final_url
=
urllib
.
request
.
urlopen
(
target
).
geturl
()
except
:
raise
ValidationError
(
"Invalid link"
)
# right now you get a 500 error... intended?
# if the host (go.gmu.edu) is in the entered target link
if
self
.
host
in
final_url
or
self
.
host
in
target
:
# not sure both logic checks necessary
except
urllib
.
error
.
URLError
as
e
:
# to permit users to enter sites that return most errors, but
# prevent them from entering sites that result in an HTTP 300 error
if
any
(
int
(
str
(
e
)[
11
:
14
])
==
errorNum
for
errorNum
in
range
(
300
,
308
)):
raise
ValidationError
(
"Link result in a 300 error"
)
# right now you get a 500 error... intended?
else
:
final_url
=
""
# if the host (go.gmu.edu) is in the entered target link or where it redirects
if
self
.
host
in
final_url
or
self
.
host
in
target
:
raise
ValidationError
(
"You can't make a Go link to Go silly!"
)
else
:
return
target
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment