summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Basnight <mbasnight@gmail.com>2012-02-28 10:49:31 -0800
committerMichael Basnight <mbasnight@gmail.com>2012-02-28 10:49:31 -0800
commit1c5da13b9fc227323f7023327c8c97e9f446353f (patch)
tree37eb536a8d7216ee8d92895c5c835374a5fef0ca
parent20cfad928c8dbae46e309f1e6150affd9d2b48c5 (diff)
downloadroutes-1c5da13b9fc227323f7023327c8c97e9f446353f.tar.gz
Added functionality to allow escaped dots in urls
* Added to regex to allow excaped dots in urls * Added tests to make sure escaped dots work and dont clobber the existing format strings --HG-- branch : trunk
-rw-r--r--routes/mapper.py4
-rw-r--r--tests/test_functional/test_resources.py22
2 files changed, 24 insertions, 2 deletions
diff --git a/routes/mapper.py b/routes/mapper.py
index 18ade09..630933f 100644
--- a/routes/mapper.py
+++ b/routes/mapper.py
@@ -1079,8 +1079,8 @@ class Mapper(SubMapperParent):
self.connect("formatted_" + name_prefix + name, formatted_path,
**route_options)
self.connect(name_prefix + name, path, **route_options)
-
- requirements_regexp = '[^\/]+'
+
+ requirements_regexp = '[^\/]+?(?<!\\\)'
# Add the routes that deal with member methods of a resource
for method, lst in member_methods.iteritems():
diff --git a/tests/test_functional/test_resources.py b/tests/test_functional/test_resources.py
index 333716b..9fd7ab9 100644
--- a/tests/test_functional/test_resources.py
+++ b/tests/test_functional/test_resources.py
@@ -127,6 +127,28 @@ class TestResourceRecognition(unittest.TestCase):
test_path('/people/2.json', 'PUT')
eq_({'controller':'people', 'action':'update', 'id':'2', 'format':'json'}, con.mapper_dict )
+ # Test for dots in urls
+ test_path('/people/2\.13', 'PUT')
+ eq_({'controller':'people', 'action':'update', 'id':'2\.13'}, con.mapper_dict)
+ test_path('/people/2\.13.xml', 'PUT')
+ eq_({'controller':'people', 'action':'update', 'id':'2\.13', 'format':'xml'}, con.mapper_dict)
+ test_path('/people/user\.name', 'PUT')
+ eq_({'controller':'people', 'action':'update', 'id':'user\.name'}, con.mapper_dict)
+ test_path('/people/user\.\.\.name', 'PUT')
+ eq_({'controller':'people', 'action':'update', 'id':'user\.\.\.name'}, con.mapper_dict)
+ test_path('/people/user\.name\.has\.dots', 'PUT')
+ eq_({'controller':'people', 'action':'update', 'id':'user\.name\.has\.dots'}, con.mapper_dict)
+ test_path('/people/user\.name\.is\.something.xml', 'PUT')
+ eq_({'controller':'people', 'action':'update', 'id':'user\.name\.is\.something', 'format':'xml'}, con.mapper_dict)
+ test_path('/people/user\.name\.ends\.with\.dot\..xml', 'PUT')
+ eq_({'controller':'people', 'action':'update', 'id':'user\.name\.ends\.with\.dot\.', 'format':'xml'}, con.mapper_dict)
+ test_path('/people/user\.name\.ends\.with\.dot\.', 'PUT')
+ eq_({'controller':'people', 'action':'update', 'id':'user\.name\.ends\.with\.dot\.'}, con.mapper_dict)
+ test_path('/people/\.user\.name\.starts\.with\.dot', 'PUT')
+ eq_({'controller':'people', 'action':'update', 'id':'\.user\.name\.starts\.with\.dot'}, con.mapper_dict)
+ test_path('/people/user\.name.json', 'PUT')
+ eq_({'controller':'people', 'action':'update', 'id':'user\.name', 'format':'json'}, con.mapper_dict)
+
def test_resource_with_nomin(self):
m = Mapper()
m.minimization = False