Decode "~" in url path

This commit is contained in:
Thibaut Courouble 2016-06-12 17:58:59 -04:00
parent d5b372e254
commit d0802988f1
2 changed files with 10 additions and 1 deletions

View file

@ -287,7 +287,8 @@ class App < Sinatra::Application
'angular~1.2' => 'angularjs~1.2'
}
get %r{\A/([\w~\.]+)(\-[\w\-]+)?(/.*)?\z} do |doc, type, rest|
get %r{\A/([\w~\.%]+)(\-[\w\-]+)?(/.*)?\z} do |doc, type, rest|
doc.sub! '%7E', '~'
return redirect "/#{DOC_REDIRECTS[doc]}#{type}#{rest}" if DOC_REDIRECTS.key?(doc)
return redirect "/angularjs/api#{rest}", 301 if doc == 'angular' && rest.start_with?('/ng')
return 404 unless @doc = find_doc(doc)

View file

@ -164,6 +164,14 @@ class AppTest < MiniTest::Spec
assert last_response.not_found?
end
it "decodes '~' properly" do
get '/html%7E5/'
assert last_response.ok?
get '/html%7E42/'
assert last_response.not_found?
end
it "redirects with trailing slash" do
get '/html'
assert last_response.redirect?