Commit 74b74e59 authored by James Lopez's avatar James Lopez

fix for import URL URI problem when URL contains a space

parent 28eea9bd
module Gitlab module Gitlab
class ImportUrl class ImportUrl
def initialize(url, credentials: nil) def initialize(url, credentials: nil)
@url = URI.parse(URI.encode(url)) @url = URI.parse(encode(url))
@credentials = credentials @credentials = credentials
end end
...@@ -37,5 +37,9 @@ module Gitlab ...@@ -37,5 +37,9 @@ module Gitlab
def valid_credentials? def valid_credentials?
credentials && credentials.is_a?(Hash) && credentials.any? credentials && credentials.is_a?(Hash) && credentials.any?
end end
def encode(url)
URI.decode(url).size < url.size ? url : URI.encode(url)
end
end end
end end
...@@ -3,19 +3,32 @@ require 'spec_helper' ...@@ -3,19 +3,32 @@ require 'spec_helper'
describe Gitlab::ImportUrl do describe Gitlab::ImportUrl do
let(:credentials) { { user: 'blah', password: 'password' } } let(:credentials) { { user: 'blah', password: 'password' } }
let(:url) { "https://github.com/me/project.git" }
let(:import_url) do let(:import_url) do
Gitlab::ImportUrl.new("https://github.com/me/project.git", credentials: credentials) described_class.new(url, credentials: credentials)
end end
describe :full_url do describe 'full_url' do
it { expect(import_url.full_url).to eq("https://blah:password@github.com/me/project.git") } it { expect(import_url.full_url).to eq("https://blah:password@github.com/me/project.git") }
end end
describe :sanitized_url do describe 'sanitized_url' do
it { expect(import_url.sanitized_url).to eq("https://github.com/me/project.git") } it { expect(import_url.sanitized_url).to eq("https://github.com/me/project.git") }
end end
describe :credentials do describe 'credentials' do
it { expect(import_url.credentials).to eq(credentials) } it { expect(import_url.credentials).to eq(credentials) }
end end
context 'URL encoding' do
describe 'not encoded URL' do
let(:url) { "https://github.com/me/my project.git" }
it { expect(import_url.sanitized_url).to eq("https://github.com/me/my%20project.git") }
end
describe 'already encoded URL' do
let(:url) { "https://github.com/me/my%20project.git" }
it { expect(import_url.sanitized_url).to eq("https://github.com/me/my%20project.git") }
end
end
end end
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