diff --git a/app/models/project.rb b/app/models/project.rb index ceebfcd733bca7246ef7e6ae65b4fde54b323d9f..64c1722ccf04e9a23ad330149e984fbb390e73fb 100644 --- a/app/models/project.rb +++ b/app/models/project.rb @@ -447,6 +447,8 @@ class Project < ActiveRecord::Base import_url = Gitlab::UrlSanitizer.new(value) create_or_update_import_data(credentials: import_url.credentials) super(import_url.sanitized_url) + rescue Addressable::URI::InvalidURIError + errors.add(:import_url, 'must be a valid URL.') end def import_url diff --git a/spec/models/project_spec.rb b/spec/models/project_spec.rb index 897b6898f54e8baee55d21862d073bb5cee2c26d..5859691a3c4f401d1e26c5515bd117e2f3ec9b9c 100644 --- a/spec/models/project_spec.rb +++ b/spec/models/project_spec.rb @@ -65,7 +65,14 @@ describe Project, models: true do end it 'should not allow an invalid URI as import_url' do - project2 = build(:project) + project2 = build(:project, import_url: 'invalid://') + + expect(project2).not_to be_valid + end + + it 'should allow a valid URI as import_url' do + project2 = build(:project, import_url: 'ssh://test@gitlab.com/project.git') + expect(project2).to be_valid end end