# HG changeset patch # User nanaya # Date 1544377125 -32400 # Node ID f11862e58af4c908883a619263856b11d505c066 # Parent 4608d12ebe030d9c947df949a27c1e589a40c2a4 Canonicalize 0-prefixed ids as well diff -r 4608d12ebe03 -r f11862e58af4 app/controllers/pastes_controller.rb --- a/app/controllers/pastes_controller.rb Mon Dec 10 02:35:08 2018 +0900 +++ b/app/controllers/pastes_controller.rb Mon Dec 10 02:38:45 2018 +0900 @@ -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 @@ 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 diff -r 4608d12ebe03 -r f11862e58af4 app/models/paste.rb --- a/app/models/paste.rb Mon Dec 10 02:35:08 2018 +0900 +++ b/app/models/paste.rb Mon Dec 10 02:38:45 2018 +0900 @@ -15,9 +15,9 @@ end def self.safe_find(raw_id) - /\A(?[0-9]+)(?:-(?[0-9a-f]+))?\z/ =~ raw_id.to_s + /\A(?[0-9]+)(?:-(?[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)