diff --git a/app/models/upload.rb b/app/models/upload.rb index b56e68a672f..140922862e7 100644 --- a/app/models/upload.rb +++ b/app/models/upload.rb @@ -177,7 +177,7 @@ class Upload < ActiveRecord::Base end return if uri&.path.blank? - data = uri.path.match(/(\/original\/\dX[\/\.\w]*\/([a-zA-Z0-9]+)[\.\w]+)/) + data = uri.path.match(/(\/original\/\dX[\/\.\w]*\/([a-zA-Z0-9]+)[\.\w]*)/) return if data.blank? sha1 = data[2] upload = nil diff --git a/spec/models/upload_spec.rb b/spec/models/upload_spec.rb index 35f0db6a9d9..0e86a0fb3ad 100644 --- a/spec/models/upload_spec.rb +++ b/spec/models/upload_spec.rb @@ -82,9 +82,16 @@ describe Upload do expect(Upload.get_from_url(upload.url)).to eq(upload) end + describe 'for an extensionless url' do + let(:url) { "/uploads/default/original/1X/#{sha1}" } + + it 'should return the right upload' do + expect(Upload.get_from_url(upload.url)).to eq(upload) + end + end + describe 'for a url without a tree' do let(:url) { "/uploads/default/original/1X/#{sha1}.png" } - let(:upload) { Fabricate(:upload, url: url, sha1: sha1) } it 'should return the right upload' do expect(Upload.get_from_url(upload.url)).to eq(upload)