]> cat aescling's git repositories - mastodon.git/commitdiff
Fix nil host in remotable (#8508)
authorRenato "Lond" Cerqueira <renato@lond.com.br>
Wed, 29 Aug 2018 19:13:49 +0000 (21:13 +0200)
committerEugen Rochko <eugen@zeonfederated.com>
Wed, 29 Aug 2018 19:13:49 +0000 (21:13 +0200)
Host can be nil in urls like
'https:https://example.com/path/file.png'

app/models/concerns/remotable.rb
spec/models/concerns/remotable_spec.rb

index c17f19a60050bb1a0916b4a9c041aade37692ca0..9372a963bf64eef747b062399d3e05639def5567 100644 (file)
@@ -18,7 +18,7 @@ module Remotable
           return
         end
 
-        return if !%w(http https).include?(parsed_url.scheme) || parsed_url.host.empty? || self[attribute_name] == url
+        return if !%w(http https).include?(parsed_url.scheme) || parsed_url.host.blank? || self[attribute_name] == url
 
         begin
           Request.new(:get, url).perform do |response|
index b39233739c03ba13fe31e81f448348426c8642cf..a4289cc45e79aca0e8e251eb1b6113007a4eabeb 100644 (file)
@@ -88,7 +88,18 @@ RSpec.describe Remotable do
 
       context 'parsed_url.host is empty' do
         it 'makes no request' do
-          parsed_url = double(scheme: 'https', host: double(empty?: true))
+          parsed_url = double(scheme: 'https', host: double(blank?: true))
+          allow(Addressable::URI).to receive_message_chain(:parse, :normalize)
+            .with(url).with(no_args).and_return(parsed_url)
+
+          foo.hoge_remote_url = url
+          expect(request).not_to have_been_requested
+        end
+      end
+
+      context 'parsed_url.host is nil' do
+        it 'makes no request' do
+          parsed_url = Addressable::URI.parse('https:https://example.com/path/file.png')
           allow(Addressable::URI).to receive_message_chain(:parse, :normalize)
             .with(url).with(no_args).and_return(parsed_url)