URI rewriting should be very liberal towards page names
This commit is contained in:
parent
12aa4365ad
commit
0d9d89ad3c
|
@ -25,7 +25,8 @@ class DispatchServlet
|
||||||
|
|
||||||
def self.parse_uri(path)
|
def self.parse_uri(path)
|
||||||
ApplicationController.logger.debug "Parsing URI '#{path}'"
|
ApplicationController.logger.debug "Parsing URI '#{path}'"
|
||||||
component = /([-_a-zA-Z0-9]+)/
|
component = '([-_a-zA-Z0-9]+)'
|
||||||
|
page_name = '(.*)'
|
||||||
case path.sub(%r{^/(?:fcgi|mruby|cgi)/}, "/")
|
case path.sub(%r{^/(?:fcgi|mruby|cgi)/}, "/")
|
||||||
when '/wiki/'
|
when '/wiki/'
|
||||||
{ :web => nil, :controller => 'wiki', :action => 'index' }
|
{ :web => nil, :controller => 'wiki', :action => 'index' }
|
||||||
|
@ -33,13 +34,21 @@ class DispatchServlet
|
||||||
{ :web => nil, :controller => 'wiki', :action => $1 }
|
{ :web => nil, :controller => 'wiki', :action => $1 }
|
||||||
when %r{^/#{component}/#{component}/?$}
|
when %r{^/#{component}/#{component}/?$}
|
||||||
{ :web => $1, :controller => 'wiki', :action => $2 }
|
{ :web => $1, :controller => 'wiki', :action => $2 }
|
||||||
when %r{^/#{component}/#{component}/#{component}/?$}
|
when %r{^/#{component}/#{component}/(.*)/?$}
|
||||||
{ :web => $1, :controller => 'wiki', :action => $2, :id => $3 }
|
{ :web => $1, :controller => 'wiki', :action => $2, :id => drop_trailing_slash($3) }
|
||||||
else
|
else
|
||||||
false
|
false
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def self.drop_trailing_slash(line)
|
||||||
|
if line[-1] == ?/
|
||||||
|
line.chop
|
||||||
|
else
|
||||||
|
line
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -472,6 +472,8 @@ class WikiControllerTest < Test::Unit::TestCase
|
||||||
|
|
||||||
def test_rss_with_headlines
|
def test_rss_with_headlines
|
||||||
setup_wiki_with_three_pages
|
setup_wiki_with_three_pages
|
||||||
|
@title_with_spaces = @wiki.write_page('wiki1', 'Title With Spaces',
|
||||||
|
'About spaces', 1.hour.ago, Author.new('TreeHugger', '127.0.0.2'))
|
||||||
|
|
||||||
@request.host = 'localhost'
|
@request.host = 'localhost'
|
||||||
@request.port = 8080
|
@request.port = 8080
|
||||||
|
@ -480,7 +482,7 @@ class WikiControllerTest < Test::Unit::TestCase
|
||||||
|
|
||||||
assert_success
|
assert_success
|
||||||
pages = r.template_objects['pages_by_revision']
|
pages = r.template_objects['pages_by_revision']
|
||||||
assert_equal [@home, @oak, @elephant], pages,
|
assert_equal [@home, @oak, @elephant, @title_with_spaces], pages,
|
||||||
"Pages are not as expected: #{pages.map {|p| p.name}.inspect}"
|
"Pages are not as expected: #{pages.map {|p| p.name}.inspect}"
|
||||||
assert r.template_objects['hide_description']
|
assert r.template_objects['hide_description']
|
||||||
|
|
||||||
|
@ -489,7 +491,8 @@ class WikiControllerTest < Test::Unit::TestCase
|
||||||
expected_page_links =
|
expected_page_links =
|
||||||
['http://localhost:8080/wiki1/show/HomePage',
|
['http://localhost:8080/wiki1/show/HomePage',
|
||||||
'http://localhost:8080/wiki1/show/Oak',
|
'http://localhost:8080/wiki1/show/Oak',
|
||||||
'http://localhost:8080/wiki1/show/Elephant']
|
'http://localhost:8080/wiki1/show/Elephant',
|
||||||
|
'http://localhost:8080/wiki1/show/Title With Spaces']
|
||||||
|
|
||||||
assert_template_xpath_match '/rss/channel/link',
|
assert_template_xpath_match '/rss/channel/link',
|
||||||
'http://localhost:8080/wiki1/show/HomePage'
|
'http://localhost:8080/wiki1/show/HomePage'
|
||||||
|
|
|
@ -35,10 +35,25 @@ class UrlRewritingHackTest < Test::Unit::TestCase
|
||||||
|
|
||||||
assert_equal false, DispatchServlet.parse_uri('')
|
assert_equal false, DispatchServlet.parse_uri('')
|
||||||
assert_equal false, DispatchServlet.parse_uri('//')
|
assert_equal false, DispatchServlet.parse_uri('//')
|
||||||
assert_equal false, DispatchServlet.parse_uri('/web/show/$HOME_PAGE')
|
|
||||||
assert_equal false, DispatchServlet.parse_uri('/web/show/HomePage/something_else')
|
|
||||||
assert_equal false, DispatchServlet.parse_uri('web')
|
assert_equal false, DispatchServlet.parse_uri('web')
|
||||||
assert_equal false, DispatchServlet.parse_uri('/web/show/HomePage?arg1=value1&arg2=value2')
|
end
|
||||||
|
|
||||||
|
def test_parse_uri_liberal_with_pagenames
|
||||||
|
|
||||||
|
assert_equal({:controller => 'wiki', :web => 'web', :action => 'show', :id => '$HOME_PAGE'},
|
||||||
|
DispatchServlet.parse_uri('/web/show/$HOME_PAGE'))
|
||||||
|
|
||||||
|
assert_equal({:controller => 'wiki', :web => 'web', :action => 'show',
|
||||||
|
:id => 'HomePage/something_else'},
|
||||||
|
DispatchServlet.parse_uri('/web/show/HomePage/something_else'))
|
||||||
|
|
||||||
|
assert_equal({:controller => 'wiki', :web => 'web', :action => 'show',
|
||||||
|
:id => 'HomePage?arg1=value1&arg2=value2'},
|
||||||
|
DispatchServlet.parse_uri('/web/show/HomePage?arg1=value1&arg2=value2'))
|
||||||
|
|
||||||
|
assert_equal({:controller => 'wiki', :web => 'web', :action => 'show',
|
||||||
|
:id => 'Page+With+Spaces'},
|
||||||
|
DispatchServlet.parse_uri('/web/show/Page+With+Spaces'))
|
||||||
end
|
end
|
||||||
|
|
||||||
def test_url_rewriting
|
def test_url_rewriting
|
||||||
|
@ -58,5 +73,4 @@ class UrlRewritingHackTest < Test::Unit::TestCase
|
||||||
ur.rewrite(:controller => 'wiki')
|
ur.rewrite(:controller => 'wiki')
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
end
|
end
|
Loading…
Reference in a new issue