From 74b74e59327ef4e393b937d33ba10c43c1e1087b Mon Sep 17 00:00:00 2001 From: James Lopez Date: Tue, 17 May 2016 15:01:03 +0200 Subject: fix for import URL URI problem when URL contains a space --- lib/gitlab/import_url.rb | 6 +++++- spec/lib/gitlab/import_url_spec.rb | 21 +++++++++++++++++---- 2 files changed, 22 insertions(+), 5 deletions(-) diff --git a/lib/gitlab/import_url.rb b/lib/gitlab/import_url.rb index d23b013c1f5..f1191cc3a50 100644 --- a/lib/gitlab/import_url.rb +++ b/lib/gitlab/import_url.rb @@ -1,7 +1,7 @@ module Gitlab class ImportUrl def initialize(url, credentials: nil) - @url = URI.parse(URI.encode(url)) + @url = URI.parse(encode(url)) @credentials = credentials end @@ -37,5 +37,9 @@ module Gitlab def valid_credentials? credentials && credentials.is_a?(Hash) && credentials.any? end + + def encode(url) + URI.decode(url).size < url.size ? url : URI.encode(url) + end end end diff --git a/spec/lib/gitlab/import_url_spec.rb b/spec/lib/gitlab/import_url_spec.rb index f758cb8693c..46029b121dc 100644 --- a/spec/lib/gitlab/import_url_spec.rb +++ b/spec/lib/gitlab/import_url_spec.rb @@ -3,19 +3,32 @@ require 'spec_helper' describe Gitlab::ImportUrl do let(:credentials) { { user: 'blah', password: 'password' } } + let(:url) { "https://github.com/me/project.git" } let(:import_url) do - Gitlab::ImportUrl.new("https://github.com/me/project.git", credentials: credentials) + described_class.new(url, credentials: credentials) 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") } end - describe :sanitized_url do + describe 'sanitized_url' do it { expect(import_url.sanitized_url).to eq("https://github.com/me/project.git") } end - describe :credentials do + describe 'credentials' do it { expect(import_url.credentials).to eq(credentials) } 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 -- cgit v1.2.1 From 8a91f3f27399745722fe527ee76ab18bc5b26245 Mon Sep 17 00:00:00 2001 From: James Lopez Date: Tue, 17 May 2016 15:04:33 +0200 Subject: added CHANGELOG --- CHANGELOG | 1 + 1 file changed, 1 insertion(+) diff --git a/CHANGELOG b/CHANGELOG index 20e2fcb806c..bcf44b9a8d3 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -61,6 +61,7 @@ v 8.8.0 (unreleased) v 8.7.6 - Fix links on wiki pages for relative url setups. !4131 (Artem Sidorenko) + - Fix import by `Any Git URL` broken if the URL contains a space v 8.7.5 - Fix relative links in wiki pages. !4050 -- cgit v1.2.1 From f2f345e6048f80e4d6510db102cd046fca43d4e4 Mon Sep 17 00:00:00 2001 From: James Lopez Date: Mon, 23 May 2016 09:05:01 +0200 Subject: avoid encoding import url and delegate good format to user --- lib/gitlab/import_url.rb | 6 +----- spec/lib/gitlab/import_url_spec.rb | 12 ------------ 2 files changed, 1 insertion(+), 17 deletions(-) diff --git a/lib/gitlab/import_url.rb b/lib/gitlab/import_url.rb index f1191cc3a50..3cfbc17b89b 100644 --- a/lib/gitlab/import_url.rb +++ b/lib/gitlab/import_url.rb @@ -1,7 +1,7 @@ module Gitlab class ImportUrl def initialize(url, credentials: nil) - @url = URI.parse(encode(url)) + @url = URI.parse(url) @credentials = credentials end @@ -37,9 +37,5 @@ module Gitlab def valid_credentials? credentials && credentials.is_a?(Hash) && credentials.any? end - - def encode(url) - URI.decode(url).size < url.size ? url : URI.encode(url) - end end end diff --git a/spec/lib/gitlab/import_url_spec.rb b/spec/lib/gitlab/import_url_spec.rb index 46029b121dc..7948386b0e6 100644 --- a/spec/lib/gitlab/import_url_spec.rb +++ b/spec/lib/gitlab/import_url_spec.rb @@ -19,16 +19,4 @@ describe Gitlab::ImportUrl do describe 'credentials' do it { expect(import_url.credentials).to eq(credentials) } 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 -- cgit v1.2.1 From d83ce65c1a0a8bcec603faf342cd2d78075ffb8d Mon Sep 17 00:00:00 2001 From: James Lopez Date: Mon, 23 May 2016 09:11:21 +0200 Subject: fix changelog and merge --- CHANGELOG | 4 +++- lib/gitlab/url_sanitizer.rb | 2 +- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index 1c26692f3ab..21b383b200d 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -83,9 +83,11 @@ v 8.8.0 - Allows MR authors to have the source branch removed when merging the MR. !2801 (Jeroen Jacobs) - When creating a .gitignore file a dropdown with templates will be provided +v 8.7.7 + - Fix import by `Any Git URL` broken if the URL contains a space + v 8.7.6 - Fix links on wiki pages for relative url setups. !4131 (Artem Sidorenko) - - Fix import by `Any Git URL` broken if the URL contains a space - Fix import from GitLab.com to a private instance failure. !4181 - Fix external imports not finding the import data. !4106 diff --git a/lib/gitlab/url_sanitizer.rb b/lib/gitlab/url_sanitizer.rb index c59d53b941a..7d02fe3c971 100644 --- a/lib/gitlab/url_sanitizer.rb +++ b/lib/gitlab/url_sanitizer.rb @@ -7,7 +7,7 @@ module Gitlab end def initialize(url, credentials: nil) - @url = Addressable::URI.parse(URI.encode(url)) + @url = Addressable::URI.parse(url) @credentials = credentials end -- cgit v1.2.1