From 9ec670c7d8518d847eb2a559984583df36b657d8 Mon Sep 17 00:00:00 2001 From: Thibaut Date: Sat, 3 Jan 2015 09:15:46 -0500 Subject: [PATCH] Fix and simplify doc route --- lib/app.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/app.rb b/lib/app.rb index 4d09aea9..1bf3b939 100644 --- a/lib/app.rb +++ b/lib/app.rb @@ -161,13 +161,13 @@ class App < Sinatra::Application redirect 'http://www.reddit.com/submit?url=http%3A%2F%2Fdevdocs.io&title=All-in-one%2C%20quickly%20searchable%20API%20docs&resubmit=true' end - get %r{\A/(\w+)(\-[\w\-]+)?(/)?(.+)?\z} do |doc, type, slash, rest| + get %r{\A/(\w+)(\-[\w\-]+)?(/.*)?\z} do |doc, type, rest| return 404 unless @doc = settings.docs[doc] - if !rest && !slash + if rest.nil? redirect "/#{doc}#{type}/" - elsif rest && rest.end_with?('/') - redirect "#{doc}#{type}#{slash}#{rest[0...-1]}" + elsif rest.length > 1 && rest.end_with?('/') + redirect "/#{doc}#{type}#{rest[0...-1]}" else erb :other end