History

Decode "~" in url path

Thibaut Courouble committed 10 years ago

Commit d0802981 parent d5b372e2 files · +10 −1Browse files

Unified · Split

2 files
  1. lib/app.rb +2 −1
  2. test/app_test.rb +8 −0
lib/app.rb+2−1
@@ -287,7 +287,8 @@ class App < Sinatra::Application · 286 unmodified lines
287 'angular~1.2' => 'angularjs~1.2'287 'angular~1.2' => 'angularjs~1.2'
288 }288 }
289 289
290 get %r{\A/([\w~\.]+)(\-[\w\-]+)?(/.*)?\z} do |doc, type, rest|290 get %r{\A/([\w~\.%]+)(\-[\w\-]+)?(/.*)?\z} do |doc, type, rest|
291 doc.sub! '%7E', '~'
291 return redirect "/#{DOC_REDIRECTS[doc]}#{type}#{rest}" if DOC_REDIRECTS.key?(doc)292 return redirect "/#{DOC_REDIRECTS[doc]}#{type}#{rest}" if DOC_REDIRECTS.key?(doc)
292 return redirect "/angularjs/api#{rest}", 301 if doc == 'angular' && rest.start_with?('/ng')293 return redirect "/angularjs/api#{rest}", 301 if doc == 'angular' && rest.start_with?('/ng')
293 return 404 unless @doc = find_doc(doc)294 return 404 unless @doc = find_doc(doc)
test/app_test.rb+8−0
@@ -164,6 +164,14 @@ class AppTest < MiniTest::Spec · 163 unmodified lines
164 assert last_response.not_found?164 assert last_response.not_found?
165 end165 end
166 166
167 it "decodes '~' properly" do
168 get '/html%7E5/'
169 assert last_response.ok?
170
171 get '/html%7E42/'
172 assert last_response.not_found?
173 end
174
167 it "redirects with trailing slash" do175 it "redirects with trailing slash" do
168 get '/html'176 get '/html'
169 assert last_response.redirect?177 assert last_response.redirect?