[PATCH conductor 2/2] BZ 811852 - DeployablesController#import_xml_from_url: fixed undefined method 'request_uri'

jzigmund at redhat.com jzigmund at redhat.com
Tue Aug 21 18:34:01 UTC 2012


From: Jozef Zigmund <jzigmund at redhat.com>

When user made typo in URL like 'http;//' instead of 'http://'
then he got "undefined method `request_uri' for #<URI::Generic:0x7fb611605c60>"

https://bugzilla.redhat.com/show_bug.cgi?id=811852
---
 src/app/controllers/deployables_controller.rb | 25 ++++++++++++++++---------
 1 file changed, 16 insertions(+), 9 deletions(-)

diff --git a/src/app/controllers/deployables_controller.rb b/src/app/controllers/deployables_controller.rb
index e07a603..8c007ff 100644
--- a/src/app/controllers/deployables_controller.rb
+++ b/src/app/controllers/deployables_controller.rb
@@ -304,17 +304,24 @@ class DeployablesController < ApplicationController
   end
 
   def import_xml_from_url(url)
-    begin
-      response = RestClient.get(url, :accept => :xml)
-      if response.code == 200
-        response
-      end
-    rescue RestClient::Exception, SocketError, URI::InvalidURIError, Errno::ECONNREFUSED, Errno::ETIMEDOUT
-      if url.present?
-        flash[:error] = t('catalog_entries.flash.warning.not_valid_or_reachable', :url => url)
+    if url.present?
+      uri = URI.parse(url)
+      if uri.kind_of?(URI::HTTP)
+        begin
+          response = RestClient.get(url, :accept => :xml)
+          if response.code == 200
+            response
+          end
+        rescue RestClient::Exception, SocketError, URI::InvalidURIError, Errno::ECONNREFUSED, Errno::ETIMEDOUT
+            flash[:error] = t('catalog_entries.flash.warning.not_valid_or_reachable', :url => url)
+            nil
+        end
       else
-        flash[:error] = t('catalog_entries.flash.warning.no_url_provided')
+        flash[:error] = t('catalog_entries.flash.warning.not_valid_or_reachable', :url => url)
+        nil
       end
+    else
+      flash[:error] = t('catalog_entries.flash.warning.no_url_provided')
       nil
     end
   end
-- 
1.7.11.4




More information about the aeolus-devel mailing list