Correct short url decoding for sha1s leading with zero
This was picked up cause we had a flaky test!
This commit is contained in:
parent
c7532003f3
commit
f766ea4257
|
@ -61,7 +61,12 @@ class Upload < ActiveRecord::Base
|
|||
def self.sha1_from_short_url(url)
|
||||
if url =~ /(upload:\/\/)?([a-zA-Z0-9]+)(\..*)?/
|
||||
sha1 = Base62.decode($2).to_s(16)
|
||||
sha1.length == 40 ? sha1 : nil
|
||||
|
||||
if sha1.length > 40
|
||||
nil
|
||||
else
|
||||
sha1.rjust(40, '0')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
@ -128,6 +128,11 @@ describe Upload do
|
|||
expect(Upload.sha1_from_short_url('upload://r3AYqESanERjladb4vBB7VsMBm6')).to eq(sha1)
|
||||
expect(Upload.sha1_from_short_url('r3AYqESanERjladb4vBB7VsMBm6')).to eq(sha1)
|
||||
end
|
||||
|
||||
it "should be able to look up sha1 even with leading zeros" do
|
||||
sha1 = '0000c513e1da04f7b4e99230851ea2aafeb8cc4e'
|
||||
expect(Upload.sha1_from_short_url('upload://1Eg9p8rrCURq4T3a6iJUk0ri6.png')).to eq(sha1)
|
||||
end
|
||||
end
|
||||
|
||||
end
|
||||
|
|
Loading…
Reference in New Issue