BigW Consortium Gitlab
Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
G
gitlab-ce
Project
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
Registry
Registry
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
Forest Godfrey
gitlab-ce
Commits
f06d370b
Commit
f06d370b
authored
Sep 13, 2017
by
Rémy Coutable
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'backport-ee-changes-to-url-sanitizer' into 'master'
Backport more EE changes to Gitlab::UrlSanitizer See merge request !14150
parents
35273121
b46d5b13
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
4 deletions
+30
-4
url_sanitizer.rb
lib/gitlab/url_sanitizer.rb
+21
-4
url_sanitizer_spec.rb
spec/lib/gitlab/url_sanitizer_spec.rb
+9
-0
No files found.
lib/gitlab/url_sanitizer.rb
View file @
f06d370b
...
@@ -19,13 +19,12 @@ module Gitlab
...
@@ -19,13 +19,12 @@ module Gitlab
end
end
def
initialize
(
url
,
credentials:
nil
)
def
initialize
(
url
,
credentials:
nil
)
@url
=
Addressable
::
URI
.
parse
(
url
.
to_s
.
strip
)
%i[user password]
.
each
do
|
symbol
|
%i[user password]
.
each
do
|
symbol
|
credentials
[
symbol
]
=
credentials
[
symbol
].
presence
if
credentials
&
.
key?
(
symbol
)
credentials
[
symbol
]
=
credentials
[
symbol
].
presence
if
credentials
&
.
key?
(
symbol
)
end
end
@credentials
=
credentials
@credentials
=
credentials
@url
=
parse_url
(
url
)
end
end
def
sanitized_url
def
sanitized_url
...
@@ -49,12 +48,30 @@ module Gitlab
...
@@ -49,12 +48,30 @@ module Gitlab
private
private
def
parse_url
(
url
)
url
=
url
.
to_s
.
strip
match
=
url
.
match
(
%r{
\A
(?:git|ssh|http(?:s?))
\:
//(?:(.+)(?:@))?(.+)}
)
raw_credentials
=
match
[
1
]
if
match
if
raw_credentials
.
present?
url
.
sub!
(
"
#{
raw_credentials
}
@"
,
''
)
user
,
password
=
raw_credentials
.
split
(
':'
)
@credentials
||=
{
user:
user
.
presence
,
password:
password
.
presence
}
end
url
=
Addressable
::
URI
.
parse
(
url
)
url
.
password
=
password
if
password
.
present?
url
.
user
=
user
if
user
.
present?
url
end
def
generate_full_url
def
generate_full_url
return
@url
unless
valid_credentials?
return
@url
unless
valid_credentials?
@full_url
=
@url
.
dup
@full_url
=
@url
.
dup
@full_url
.
password
=
credentials
[
:password
]
@full_url
.
password
=
credentials
[
:password
]
if
credentials
[
:password
].
present?
@full_url
.
user
=
credentials
[
:user
]
@full_url
.
user
=
credentials
[
:user
]
if
credentials
[
:user
].
present?
@full_url
@full_url
end
end
...
...
spec/lib/gitlab/url_sanitizer_spec.rb
View file @
f06d370b
...
@@ -174,4 +174,13 @@ describe Gitlab::UrlSanitizer do
...
@@ -174,4 +174,13 @@ describe Gitlab::UrlSanitizer do
end
end
end
end
end
end
context
'when credentials contains special chars'
do
it
'should parse the URL without errors'
do
url_sanitizer
=
described_class
.
new
(
"https://foo:b?r@github.com/me/project.git"
)
expect
(
url_sanitizer
.
sanitized_url
).
to
eq
(
"https://github.com/me/project.git"
)
expect
(
url_sanitizer
.
full_url
).
to
eq
(
"https://foo:b?r@github.com/me/project.git"
)
end
end
end
end
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment