Commit c92808ed authored by Toon Claes's avatar Toon Claes

Fix for creating a project through API when import_url is nil

The API was returning 500 when `nil` is passed for the `import_url`.

In fact, it was `Gitlab::UrlSanitizer.valid?` which was throwing a
`NoMethodError` when `nil` value was passed.
parent 7a7f4877
---
title: Fix for creating a project through API when import_url is nil
merge_request: 9841
author:
...@@ -9,6 +9,8 @@ module Gitlab ...@@ -9,6 +9,8 @@ module Gitlab
end end
def self.valid?(url) def self.valid?(url)
return false unless url
Addressable::URI.parse(url.strip) Addressable::URI.parse(url.strip)
true true
......
...@@ -70,4 +70,12 @@ describe Gitlab::UrlSanitizer, lib: true do ...@@ -70,4 +70,12 @@ describe Gitlab::UrlSanitizer, lib: true do
expect(sanitizer.full_url).to eq('user@server:project.git') expect(sanitizer.full_url).to eq('user@server:project.git')
end end
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 end
...@@ -424,6 +424,14 @@ describe API::Projects, api: true do ...@@ -424,6 +424,14 @@ describe API::Projects, api: true do
expect(json_response['only_allow_merge_if_all_discussions_are_resolved']).to be_truthy expect(json_response['only_allow_merge_if_all_discussions_are_resolved']).to be_truthy
end 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 context 'when a visibility level is restricted' do
let(:project_param) { attributes_for(:project, visibility: 'public') } let(:project_param) { attributes_for(:project, visibility: 'public') }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment