Skip to content

Commit c569288

Browse files
committed
Fix Router#path_parent to not break on double slash.
1 parent 07af9c5 commit c569288

3 files changed

Lines changed: 39 additions & 5 deletions

File tree

TODO.md

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,13 @@
1-
- Test HEAD requests for:
2-
- markdown
3-
- static files
1+
- add support for applets
2+
3+
- can be implemented as separate gems
4+
- can route requests to a different directory (i.e. inside the gem directory)
5+
- simple way to instantiate and setup the applet
6+
- as a first example, implement an auth/signin applet:
7+
- session hook
8+
- session persistence
9+
- login page
10+
- support for custom behaviour and custom workflows (2FA, signin using OTP etc.)
411

512
- Some standard middleware:
613

lib/syntropy/router.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,8 @@ def path_abs(path, base)
8484
def path_parent(path)
8585
return nil if path == '/'
8686

87-
path.match(PATH_PARENT_RE)[1] || '/'
87+
m = path.match(PATH_PARENT_RE)
88+
m && (m[1] || '/')
8889
end
8990

9091
MD_EXT_RE = /\.md$/

test/test_router.rb

Lines changed: 27 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ def full_path(fn)
2424
File.join(APP_ROOT, fn)
2525
end
2626

27-
def test_find_route
27+
def test_routing
2828
# entry = @router['/']
2929
# assert_equal :not_found, entry[:kind]
3030

@@ -50,6 +50,9 @@ def test_find_route
5050
assert_equal :module, entry[:kind]
5151
assert_equal full_path('api+.rb'), entry[:fn]
5252

53+
entry = @router['/test/api//foo/bar']
54+
assert_equal :not_found, entry[:kind]
55+
5356
entry = @router['/test/api/foo/../bar']
5457
assert_equal :not_found, entry[:kind]
5558

@@ -87,4 +90,27 @@ def test_router_file_watching
8790
ensure
8891
IO.write(@tmp_fn, orig_body) if orig_body
8992
end
93+
94+
def test_malformed_path_routing
95+
entry = @router['//xmlrpc.php?rsd']
96+
assert_equal :not_found, entry[:kind]
97+
98+
entry = @router['/test//xmlrpc.php?rsd']
99+
assert_equal :not_found, entry[:kind]
100+
101+
entry = @router['/test///xmlrpc.php?rsd']
102+
assert_equal :not_found, entry[:kind]
103+
104+
entry = @router['/test///xmlrpc.php?rsd']
105+
assert_equal :not_found, entry[:kind]
106+
107+
entry = @router['/test/./qsdf']
108+
assert_equal :not_found, entry[:kind]
109+
110+
entry = @router['/test/../../lib/syntropy.rb']
111+
assert_equal :not_found, entry[:kind]
112+
113+
entry = @router['/../../lib/syntropy.rb']
114+
assert_equal :not_found, entry[:kind]
115+
end
90116
end

0 commit comments

Comments
 (0)