diff --git a/lib/app.rb b/lib/app.rb index 0a81853c..707a77b4 100644 --- a/lib/app.rb +++ b/lib/app.rb @@ -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) diff --git a/test/app_test.rb b/test/app_test.rb index 50cf78e4..03bfe1f7 100644 --- a/test/app_test.rb +++ b/test/app_test.rb @@ -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?