From: Jozef Zigmund <[email protected]> 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/images_controller.rb | 28 +++++++++++++++++++--------- src/config/locales/en.yml | 1 + 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/app/controllers/images_controller.rb b/src/app/controllers/images_controller.rb index d9ab289..7be1849 100644 --- a/src/app/controllers/images_controller.rb +++ b/src/app/controllers/images_controller.rb @@ -216,21 +216,31 @@ class ImagesController < ApplicationController @environment = PoolFamily.find(params[:environment]) check_permissions @name = params[:name] - if params.has_key? :image_url - url = params[:image_url] - begin - xml_source = RestClient.get(url, :accept => :xml) - rescue RestClient::Exception, SocketError, URI::InvalidURIError, Errno::ECONNREFUSED, Errno::ETIMEDOUT - flash.now[:error] = t('images.flash.error.invalid_url') - render :new and return + if params[:image_url].present? + url = params[:image_url] + uri = URI.parse(url) + if uri.kind_of?(URI::HTTP) + begin + xml_source = RestClient.get(url, :accept => :xml) + rescue RestClient::Exception, SocketError, URI::InvalidURIError, Errno::ECONNREFUSED, Errno::ETIMEDOUT + flash[:error] = t('images.flash.error.invalid_url') + redirect_to new_image_path(:environment => @environment) and return + end + else + flash[:error] = t('images.flash.error.invalid_url') + redirect_to new_image_path(:environment => @environment) and return + end + else + flash[:error] = t('images.flash.error.no_url') + redirect_to new_image_path(:environment => @environment) and return end else file = params[:image_file] xml_source = file && file.read unless xml_source - flash.now[:error] = t('images.flash.error.no_file') - render :new and return + flash[:error] = t('images.flash.error.no_file') + redirect_to new_image_path(:environment => @environment) and return end end diff --git a/src/config/locales/en.yml b/src/config/locales/en.yml index 8d2fb7d..99765c3 100644 --- a/src/config/locales/en.yml +++ b/src/config/locales/en.yml @@ -968,6 +968,7 @@ en: no_template: "The Image doesn't have an Image Template because it was originally imported, rather than built in Conductor." no_provider_accounts: "Images cannot be built. There are no enabled Provider Accounts associated with this Environment." no_provider_accounts_for_import: "Images cannot be imported. No Provider Accounts are currently enabled for this Environment." + no_url: URL for Image Template XML can't be blank new: new_image: New Image description: -- 1.7.11.4
