Skip to content

Commit d080298

Browse files
committed
Decode "~" in url path
1 parent d5b372e commit d080298

2 files changed

Lines changed: 10 additions & 1 deletion

File tree

lib/app.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -287,7 +287,8 @@ def supports_js_redirection?
287287
'angular~1.2' => 'angularjs~1.2'
288288
}
289289

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', '~'
291292
return redirect "/#{DOC_REDIRECTS[doc]}#{type}#{rest}" if DOC_REDIRECTS.key?(doc)
292293
return redirect "/angularjs/api#{rest}", 301 if doc == 'angular' && rest.start_with?('/ng')
293294
return 404 unless @doc = find_doc(doc)

test/app_test.rb

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -164,6 +164,14 @@ def app
164164
assert last_response.not_found?
165165
end
166166

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+
167175
it "redirects with trailing slash" do
168176
get '/html'
169177
assert last_response.redirect?

0 commit comments

Comments
 (0)