comparison app/models/paste.rb @ 464:f11862e58af4

Canonicalize 0-prefixed ids as well
author nanaya <me@nanaya.pro>
date Mon, 10 Dec 2018 02:38:45 +0900
parents b445318de858
children 02d043b1967d
comparison
equal deleted inserted replaced
463:4608d12ebe03 464:f11862e58af4
13 def to_param 13 def to_param
14 path 14 path
15 end 15 end
16 16
17 def self.safe_find(raw_id) 17 def self.safe_find(raw_id)
18 /\A(?<id>[0-9]+)(?:-(?<secret>[0-9a-f]+))?\z/ =~ raw_id.to_s 18 /\A(?<id>[0-9]+)(?:-(?<secret>[0-9a-f]+))?\z/i =~ raw_id.to_s
19 19
20 find_by(:secret => secret, :id => id) 20 find_by(:secret => secret.try(:downcase), :id => id)
21 end 21 end
22 22
23 def self.graceful_create(params) 23 def self.graceful_create(params)
24 paste = new(params) 24 paste = new(params)
25 fresh = true 25 fresh = true