Canonicalize 0-prefixed ids as well
2 files changed, 9 insertions(+), 11 deletions(-)

M app/controllers/pastes_controller.rb
M app/models/paste.rb
M app/controllers/pastes_controller.rb +7 -9
@@ 1,12 1,17 @@ 
 class PastesController < ApplicationController
-  before_action :lowercase_path, :only => :show
-
   # GET /1
   # GET /1.txt
   def show
     @paste = Paste.safe_find(params[:id])
     return head :not_found unless @paste
 
+    if params[:id] != @paste.to_param
+      redirect_to :action => :show,
+        :id => @paste.to_param,
+        :format => params[:format]
+      return
+    end
+
     respond_to do |format|
       format.html
       format.txt

          
@@ 60,13 65,6 @@ class PastesController < ApplicationCont
 
   private
 
-  def lowercase_path
-    correct_path = request.fullpath.downcase
-    return if correct_path == request.fullpath
-
-    redirect_to correct_path, :status => :moved_permanently
-  end
-
   def paste_params
     params.require(:paste).permit(:paste, :paste_gzip, :paste_gzip_base64, :is_private, :key, :language)
   end

          
M app/models/paste.rb +2 -2
@@ 15,9 15,9 @@ class Paste < ApplicationRecord
   end
 
   def self.safe_find(raw_id)
-    /\A(?<id>[0-9]+)(?:-(?<secret>[0-9a-f]+))?\z/ =~ raw_id.to_s
+    /\A(?<id>[0-9]+)(?:-(?<secret>[0-9a-f]+))?\z/i =~ raw_id.to_s
 
-    find_by(:secret => secret, :id => id)
+    find_by(:secret => secret.try(:downcase), :id => id)
   end
 
   def self.graceful_create(params)