summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoraib <aibok42@gmail.com>2019-01-02 15:36:10 +0300
committerStephen Finucane <stephen@that.guru>2019-06-11 15:38:58 +0100
commit3c01ff0ecee7abdd25a5812c5d3a9bfcb1df732d (patch)
treea67d14bb43495024c591ccb2fe989f8099da15ad
parentaeb67cd762f45108f1dd0289127e4fe1b9f674ac (diff)
downloadroutes-3c01ff0ecee7abdd25a5812c5d3a9bfcb1df732d.tar.gz
Add tests for backslash escapes in route paths
Co-Authored-By: Stephen Finucane <stephen@that.guru>
-rw-r--r--tests/test_units/test_route_escapes.py38
1 files changed, 38 insertions, 0 deletions
diff --git a/tests/test_units/test_route_escapes.py b/tests/test_units/test_route_escapes.py
new file mode 100644
index 0000000..5db07c4
--- /dev/null
+++ b/tests/test_units/test_route_escapes.py
@@ -0,0 +1,38 @@
+import unittest
+from routes.route import Route
+
+
+class TestRouteEscape(unittest.TestCase):
+ def test_normal_route(self):
+ r = Route('test', '/foo/bar')
+ self.assertEqual(r.routelist, ['/foo/bar'])
+
+ def test_route_with_backslash(self):
+ r = Route('test', '/foo\\\\bar')
+ self.assertEqual(r.routelist, ['/foo\\bar'])
+
+ def test_route_with_random_escapes(self):
+ r = Route('test', '\\/f\\oo\\/ba\\r')
+ self.assertEqual(r.routelist, ['\\/f\\oo\\/ba\\r'])
+
+ def test_route_with_colon(self):
+ r = Route('test', '/foo:bar/baz')
+ self.assertEqual(
+ r.routelist, ['/foo', {'name': 'bar', 'type': ':'}, '/', 'baz'])
+
+ def test_route_with_escaped_colon(self):
+ r = Route('test', '/foo\\:bar/baz')
+ self.assertEqual(r.routelist, ['/foo:bar/baz'])
+
+ def test_route_with_both_colons(self):
+ r = Route('test', '/prefix/escaped\\:escaped/foo=:notescaped/bar=42')
+ self.assertEqual(
+ r.routelist, ['/prefix/escaped:escaped/foo=',
+ {'name': 'notescaped', 'type': ':'}, '/', 'bar=42'])
+
+ def test_route_with_all_escapes(self):
+ r = Route('test', '/hmm\\:\\*\\{\\}*star/{brackets}/:colon')
+ self.assertEqual(
+ r.routelist, ['/hmm:*{}', {'name': 'star', 'type': '*'}, '/',
+ {'name': 'brackets', 'type': ':'}, '/',
+ {'name': 'colon', 'type': ':'}])