Skip to content
This repository was archived by the owner on Dec 7, 2018. It is now read-only.

Commit d1ee139

Browse files
committed
Fix location redirect for external links
1 parent 74bfa07 commit d1ee139

File tree

1 file changed

+6
-10
lines changed

1 file changed

+6
-10
lines changed

gitblog.py

+6-10
Original file line numberDiff line numberDiff line change
@@ -165,19 +165,15 @@ def handler(req):
165165
# Resolve symlink
166166
while requested_object.type == 'blob' and requested_object.mode == requested_object.link_mode:
167167
try:
168-
link_requested_path = normpath('/'.join(requested_path[:-1]) + '/' + \
169-
requested_object.data_stream.read().decode('utf-8'))
170-
requested_path = link_requested_path.strip('/').split('/')
171-
requested_path = list(filter(None, requested_path))
168+
link_target = requested_object.data_stream.read().decode('utf-8')
172169

173-
redirect_target = '/'.join(requested_path)
174170
# TODO: Moved protocol values for verfication
175171
# to program parameters
176-
if not redirect_target[0:7] == 'http://' and \
177-
not redirect_target[0:8] == 'https://':
178-
redirect_target = '/' + redirect_target
179-
180-
req.headers_out.add('Location', redirect_target)
172+
if link_target[0:7] == 'http://' or \
173+
link_target[0:8] == 'https://':
174+
req.headers_out.add('Location', link_target)
175+
else:
176+
req.headers_out.add('Location', '/' + link_target)
181177
return(getattr(apache, config['gitblog.redirect_code']))
182178
except:
183179
return(apache.HTTP_NOT_FOUND)

0 commit comments

Comments
 (0)