22import os .path as path
33import random
44import sys
5- from urllib .parse import quote , unquote
5+ from urllib .parse import unquote
6+ import urllib .parse
67
78from flask import Flask , request , redirect , url_for , abort
89
1213from .answer_scorer import build_quiz_answer , parse_form_content , score_submission
1314
1415
16+ def quote (s ):
17+ return urllib .parse .quote (s , safe = '' )
18+
19+
1520CSS = """
1621""" + DEFAULT_CSS + """
1722<style type="text/css">
@@ -91,7 +96,8 @@ def root():
9196 if GIFT_SCRIPT_INFO .stdin_cache :
9297 return redirect ("/-" )
9398 elif GIFT_SCRIPT_INFO .script_file :
94- return redirect ("/" + quote (GIFT_SCRIPT_INFO .script_file ))
99+ fbody = path .split (GIFT_SCRIPT_INFO .script_file )[1 ]
100+ return redirect ("/" + quote (fbody ))
95101 elif GIFT_SCRIPT_INFO .dir :
96102 scripts = [f for f in os .listdir (GIFT_SCRIPT_INFO .dir ) if f .endswith ('.gift' )]
97103 scripts .sort ()
@@ -139,14 +145,15 @@ def _quiz(giftscript_unquoted, cache=None):
139145
140146@app .route ('/<giftscript>' , methods = ['GET' ])
141147def quiz (giftscript ):
142- giftscript_unquoted = unquote (giftscript )
143148 if GIFT_SCRIPT_INFO .stdin_cache :
144- if giftscript_unquoted == '-' :
145- return _quiz (giftscript_unquoted , cache = GIFT_SCRIPT_INFO .stdin_cache )
149+ if giftscript == '-' :
150+ return _quiz (giftscript , cache = GIFT_SCRIPT_INFO .stdin_cache )
146151 elif GIFT_SCRIPT_INFO .script_file :
147- if giftscript_unquoted == GIFT_SCRIPT_INFO .script_file :
148- return _quiz (giftscript_unquoted )
152+ fbody = path .split (GIFT_SCRIPT_INFO .script_file )[1 ]
153+ if giftscript == quote (fbody ):
154+ return _quiz (GIFT_SCRIPT_INFO .script_file )
149155 elif GIFT_SCRIPT_INFO .dir :
156+ giftscript_unquoted = unquote (giftscript )
150157 scripts = [f for f in os .listdir (GIFT_SCRIPT_INFO .dir ) if f .endswith ('.gift' )]
151158 scripts .sort ()
152159 if giftscript_unquoted in scripts :
@@ -163,15 +170,16 @@ def _answer_table(giftscript_unquoted, cache=None):
163170
164171@app .route ('/<giftscript>/submit_answer' , methods = ['POST' ])
165172def submit_answer (giftscript ):
166- giftscript_unquoted = unquote (giftscript )
167173 answer_table = None
168174 if GIFT_SCRIPT_INFO .stdin_cache :
169- if giftscript_unquoted == '-' :
170- answer_table = _answer_table (giftscript_unquoted , cache = GIFT_SCRIPT_INFO .stdin_cache )
175+ if giftscript == '-' :
176+ answer_table = _answer_table (giftscript , cache = GIFT_SCRIPT_INFO .stdin_cache )
171177 elif GIFT_SCRIPT_INFO .script_file :
172- if giftscript_unquoted == GIFT_SCRIPT_INFO .script_file :
173- answer_table = _answer_table (giftscript_unquoted )
178+ fbody = path .split (GIFT_SCRIPT_INFO .script_file )[1 ]
179+ if giftscript == quote (fbody ):
180+ answer_table = _answer_table (GIFT_SCRIPT_INFO .script_file )
174181 elif GIFT_SCRIPT_INFO .dir :
182+ giftscript_unquoted = unquote (giftscript )
175183 scripts = [f for f in os .listdir (GIFT_SCRIPT_INFO .dir ) if f .endswith ('.gift' )]
176184 scripts .sort ()
177185 if giftscript_unquoted in scripts :
0 commit comments