diff options
-rw-r--r-- | changelogs/unreleased/tc-fix-project-create-500.yml | 4 | ||||
-rw-r--r-- | lib/gitlab/url_sanitizer.rb | 2 | ||||
-rw-r--r-- | spec/lib/gitlab/url_sanitizer_spec.rb | 8 | ||||
-rw-r--r-- | spec/requests/api/projects_spec.rb | 8 |
4 files changed, 22 insertions, 0 deletions
diff --git a/changelogs/unreleased/tc-fix-project-create-500.yml b/changelogs/unreleased/tc-fix-project-create-500.yml new file mode 100644 index 00000000000..1b746a41eab --- /dev/null +++ b/changelogs/unreleased/tc-fix-project-create-500.yml @@ -0,0 +1,4 @@ +--- +title: Fix for creating a project through API when import_url is nil +merge_request: 9841 +author: diff --git a/lib/gitlab/url_sanitizer.rb b/lib/gitlab/url_sanitizer.rb index f2a0e2e8d13..9ce13feb79a 100644 --- a/lib/gitlab/url_sanitizer.rb +++ b/lib/gitlab/url_sanitizer.rb @@ -9,6 +9,8 @@ module Gitlab end def self.valid?(url) + return false unless url + Addressable::URI.parse(url.strip) true diff --git a/spec/lib/gitlab/url_sanitizer_spec.rb b/spec/lib/gitlab/url_sanitizer_spec.rb index fc144a2556a..5f7abdd04fb 100644 --- a/spec/lib/gitlab/url_sanitizer_spec.rb +++ b/spec/lib/gitlab/url_sanitizer_spec.rb @@ -100,4 +100,12 @@ describe Gitlab::UrlSanitizer, lib: true do it { expect(url_sanitizer.full_url).to eq("https://john.doe@github.com/me/project.git") } end end + + describe '.valid?' do + it 'validates url strings' do + expect(described_class.valid?(nil)).to be(false) + expect(described_class.valid?('valid@project:url.git')).to be(true) + expect(described_class.valid?('123://invalid:url')).to be(false) + end + end end diff --git a/spec/requests/api/projects_spec.rb b/spec/requests/api/projects_spec.rb index 77f79cd5bc7..b4b23617498 100644 --- a/spec/requests/api/projects_spec.rb +++ b/spec/requests/api/projects_spec.rb @@ -424,6 +424,14 @@ describe API::Projects, api: true do expect(json_response['only_allow_merge_if_all_discussions_are_resolved']).to be_truthy end + it 'ignores import_url when it is nil' do + project = attributes_for(:project, { import_url: nil }) + + post api('/projects', user), project + + expect(response).to have_http_status(201) + end + context 'when a visibility level is restricted' do let(:project_param) { attributes_for(:project, visibility: 'public') } |