Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
G
gitlab-ce
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
1
Merge Requests
1
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
nexedi
gitlab-ce
Commits
a559ded4
Commit
a559ded4
authored
Mar 30, 2017
by
Ruben Davila
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Bugfix: Error at parsing URL with special chars in credentials
parent
7a6520c8
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
30 additions
and
3 deletions
+30
-3
lib/gitlab/url_sanitizer.rb
lib/gitlab/url_sanitizer.rb
+21
-3
spec/lib/gitlab/url_sanitizer_spec.rb
spec/lib/gitlab/url_sanitizer_spec.rb
+9
-0
No files found.
lib/gitlab/url_sanitizer.rb
View file @
a559ded4
...
@@ -25,8 +25,8 @@ module Gitlab
...
@@ -25,8 +25,8 @@ module Gitlab
end
end
def
initialize
(
url
,
credentials:
nil
)
def
initialize
(
url
,
credentials:
nil
)
@url
=
Addressable
::
URI
.
parse
(
url
.
strip
)
@credentials
=
credentials
@credentials
=
credentials
@url
=
parse_url
(
url
)
end
end
def
sanitized_url
def
sanitized_url
...
@@ -35,8 +35,8 @@ module Gitlab
...
@@ -35,8 +35,8 @@ module Gitlab
def
masked_url
def
masked_url
url
=
@url
.
dup
url
=
@url
.
dup
url
.
password
=
"*****"
unless
url
.
password
.
nil?
url
.
password
=
"*****"
if
url
.
password
url
.
user
=
"*****"
unless
url
.
user
.
nil?
url
.
user
=
"*****"
if
url
.
user
url
.
to_s
url
.
to_s
end
end
...
@@ -50,6 +50,24 @@ module Gitlab
...
@@ -50,6 +50,24 @@ module Gitlab
private
private
def
parse_url
(
url
)
url
=
url
.
strip
match
=
url
.
match
(
%r{
\A
(?: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
,
password:
password
}
end
url
=
Addressable
::
URI
.
parse
(
url
)
url
.
user
=
user
url
.
password
=
password
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
...
...
spec/lib/gitlab/url_sanitizer_spec.rb
View file @
a559ded4
...
@@ -100,4 +100,13 @@ describe Gitlab::UrlSanitizer, lib: true do
...
@@ -100,4 +100,13 @@ describe Gitlab::UrlSanitizer, lib: true do
it
{
expect
(
url_sanitizer
.
full_url
).
to
eq
(
"https://john.doe@github.com/me/project.git"
)
}
it
{
expect
(
url_sanitizer
.
full_url
).
to
eq
(
"https://john.doe@github.com/me/project.git"
)
}
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