change in way args are parsed and less test_routes.py
This commit is contained in:
@@ -1 +1 @@
|
|||||||
Version 2.7.4-stable+timestamp.2013.11.01.18.48.46
|
Version 2.7.4-stable+timestamp.2013.11.01.20.10.58
|
||||||
|
|||||||
+5
-6
@@ -53,7 +53,7 @@ regex_version = re.compile(r'^(_[\d]+\.[\d]+\.[\d]+)$')
|
|||||||
# apps in routes_apps_raw must parse raw_args into args
|
# apps in routes_apps_raw must parse raw_args into args
|
||||||
|
|
||||||
regex_url = re.compile('^/((?P<a>\w+)(/(?P<c>\w+)(/(?P<z>(?P<f>\w+)(\.(?P<e>[\w.]+))?(?P<s>.*)))?)?)?$')
|
regex_url = re.compile('^/((?P<a>\w+)(/(?P<c>\w+)(/(?P<z>(?P<f>\w+)(\.(?P<e>[\w.]+))?(?P<s>.*)))?)?)?$')
|
||||||
regex_args = re.compile('^[/\w@=-]*(\.[/\w@=-]+)*$')
|
regex_args = re.compile('[^\w/.@=-]')
|
||||||
|
|
||||||
|
|
||||||
def _router_default():
|
def _router_default():
|
||||||
@@ -623,7 +623,7 @@ def regex_url_in(request, environ):
|
|||||||
# ##################################################
|
# ##################################################
|
||||||
|
|
||||||
path = urllib.unquote(request.env.path_info) or '/'
|
path = urllib.unquote(request.env.path_info) or '/'
|
||||||
path = path.replace('\\', '/').replace(' ','_')
|
path = path.replace('\\', '/')
|
||||||
if path.endswith('/') and len(path) > 1:
|
if path.endswith('/') and len(path) > 1:
|
||||||
path = path[:-1]
|
path = path[:-1]
|
||||||
match = regex_url.match(path)
|
match = regex_url.match(path)
|
||||||
@@ -634,7 +634,7 @@ def regex_url_in(request, environ):
|
|||||||
request.raw_args = request.raw_args[1:]
|
request.raw_args = request.raw_args[1:]
|
||||||
if match.group('c') == 'static':
|
if match.group('c') == 'static':
|
||||||
application = match.group('a')
|
application = match.group('a')
|
||||||
version, filename = None, match.group('z')
|
version, filename = None, match.group('z').replace(' ','_')
|
||||||
if not filename:
|
if not filename:
|
||||||
raise HTTP(404)
|
raise HTTP(404)
|
||||||
items = filename.split('/', 1)
|
items = filename.split('/', 1)
|
||||||
@@ -658,10 +658,9 @@ def regex_url_in(request, environ):
|
|||||||
if request.application in routes.routes_apps_raw:
|
if request.application in routes.routes_apps_raw:
|
||||||
# application is responsible for parsing args
|
# application is responsible for parsing args
|
||||||
request.args = None
|
request.args = None
|
||||||
elif not regex_args.match(request.raw_args):
|
|
||||||
invalid_url(routes)
|
|
||||||
elif request.raw_args:
|
elif request.raw_args:
|
||||||
request.args = List(request.raw_args.split('/'))
|
args = regex_args.sub('_',request.raw_args)
|
||||||
|
request.args = List(args.split('/'))
|
||||||
else:
|
else:
|
||||||
request.args = List([])
|
request.args = List([])
|
||||||
return (None, None, environ)
|
return (None, None, environ)
|
||||||
|
|||||||
+10
-10
@@ -190,16 +190,16 @@ default_application = 'defapp'
|
|||||||
self.assertRaises(HTTP, filter_url, 'http://domain.com/ctl/bad!fcn')
|
self.assertRaises(HTTP, filter_url, 'http://domain.com/ctl/bad!fcn')
|
||||||
self.assertRaises(
|
self.assertRaises(
|
||||||
HTTP, filter_url, 'http://domain.com/ctl/fcn.bad!ext')
|
HTTP, filter_url, 'http://domain.com/ctl/fcn.bad!ext')
|
||||||
self.assertRaises(
|
#self.assertRaises(
|
||||||
HTTP, filter_url, 'http://domain.com/ctl/fcn/bad!arg')
|
# HTTP, filter_url, 'http://domain.com/ctl/fcn/bad!arg')
|
||||||
try:
|
#try:
|
||||||
# 2.7+ only
|
# # 2.7+ only
|
||||||
self.assertRaisesRegexp(HTTP, '400 BAD REQUEST \[invalid path\]', filter_url, 'http://domain.com/init/bad!ctl')
|
# self.assertRaisesRegexp(HTTP, '400 BAD REQUEST \[invalid path\]', filter_url, 'http://domain.com/init/bad!ctl')
|
||||||
self.assertRaisesRegexp(HTTP, '400 BAD REQUEST \[invalid path\]', filter_url, 'http://domain.com/init/ctlr/bad!fcn')
|
# self.assertRaisesRegexp(HTTP, '400 BAD REQUEST \[invalid path\]', filter_url, 'http://domain.com/init/ctlr/bad!fcn')
|
||||||
self.assertRaisesRegexp(HTTP, '400 BAD REQUEST \[invalid path\]', filter_url, 'http://domain.com/init/ctlr/fcn.bad!ext')
|
# self.assertRaisesRegexp(HTTP, '400 BAD REQUEST \[invalid path\]', filter_url, 'http://domain.com/init/ctlr/fcn.bad!ext')
|
||||||
self.assertRaisesRegexp(HTTP, '400 BAD REQUEST \[invalid path\]', filter_url, 'http://domain.com/appc/init/fcn/bad!arg')
|
# self.assertRaisesRegexp(HTTP, '400 BAD REQUEST \[invalid path\]', filter_url, 'http://domain.com/appc/init/fcn/bad!arg')
|
||||||
except AttributeError:
|
#except AttributeError:
|
||||||
pass
|
# pass
|
||||||
|
|
||||||
self.assertEqual(filter_url('http://domain.com/welcome/default/fcn_1'),
|
self.assertEqual(filter_url('http://domain.com/welcome/default/fcn_1'),
|
||||||
"/welcome/default/fcn_1")
|
"/welcome/default/fcn_1")
|
||||||
|
|||||||
Reference in New Issue
Block a user