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
0
Merge Requests
0
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
Jérome Perrin
gitlab-ce
Commits
0c7dd30c
Commit
0c7dd30c
authored
May 30, 2017
by
Douwe Maan
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Make .gitmodules parsing more resilient to syntax errors
parent
8039b9c3
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
47 additions
and
16 deletions
+47
-16
changelogs/unreleased/dm-gitmodules-parsing.yml
changelogs/unreleased/dm-gitmodules-parsing.yml
+4
-0
lib/gitlab/git/repository.rb
lib/gitlab/git/repository.rb
+30
-16
spec/lib/gitlab/git/repository_spec.rb
spec/lib/gitlab/git/repository_spec.rb
+13
-0
No files found.
changelogs/unreleased/dm-gitmodules-parsing.yml
0 → 100644
View file @
0c7dd30c
---
title
:
Make .gitmodules parsing more resilient to syntax errors
merge_request
:
author
:
lib/gitlab/git/repository.rb
View file @
0c7dd30c
...
@@ -1008,25 +1008,34 @@ module Gitlab
...
@@ -1008,25 +1008,34 @@ module Gitlab
def
parse_gitmodules
(
commit
,
content
)
def
parse_gitmodules
(
commit
,
content
)
results
=
{}
results
=
{}
current
=
""
name
=
nil
content
.
split
(
"
\n
"
).
each
do
|
txt
|
entry
=
nil
if
txt
=~
/^\s*\[/
content
.
each_line
do
|
line
|
current
=
txt
.
match
(
/(?<=").*(?=")/
)[
0
]
case
line
.
strip
results
[
current
]
=
{}
when
/\A\[submodule "(?<name>[^"]+)"\]\z/
# Submodule header
else
name
=
$~
[
:name
]
next
unless
results
[
current
]
entry
=
results
[
name
]
=
{}
match_data
=
txt
.
match
(
/(\w+)\s*=\s*(.*)/
)
when
/\A(?<key>\w+)\s*=\s*(?<value>.*)\z/
# Key/value pair
next
unless
match_data
key
=
$~
[
:key
]
target
=
match_data
[
2
].
chomp
value
=
$~
[
:value
].
chomp
results
[
current
][
match_data
[
1
]]
=
target
next
unless
name
&&
entry
if
match_data
[
1
]
==
"path"
entry
[
key
]
=
value
if
key
==
'path'
begin
begin
results
[
current
][
"id"
]
=
blob_content
(
commit
,
target
)
entry
[
'id'
]
=
blob_content
(
commit
,
value
)
rescue
InvalidBlobName
rescue
InvalidBlobName
results
.
delete
(
current
)
# The current entry is invalid
results
.
delete
(
name
)
name
=
entry
=
nil
end
end
end
end
when
/\A#/
# Comment
next
else
# Invalid line
name
=
entry
=
nil
end
end
end
end
...
@@ -1086,7 +1095,12 @@ module Gitlab
...
@@ -1086,7 +1095,12 @@ module Gitlab
elsif
tmp_entry
.
nil?
elsif
tmp_entry
.
nil?
return
nil
return
nil
else
else
begin
tmp_entry
=
rugged
.
lookup
(
tmp_entry
[
:oid
])
tmp_entry
=
rugged
.
lookup
(
tmp_entry
[
:oid
])
rescue
Rugged
::
OdbError
,
Rugged
::
InvalidError
,
Rugged
::
ReferenceError
return
nil
end
return
nil
unless
tmp_entry
.
type
==
:tree
return
nil
unless
tmp_entry
.
type
==
:tree
tmp_entry
=
tmp_entry
[
dir
]
tmp_entry
=
tmp_entry
[
dir
]
end
end
...
...
spec/lib/gitlab/git/repository_spec.rb
View file @
0c7dd30c
...
@@ -381,6 +381,19 @@ describe Gitlab::Git::Repository, seed_helper: true do
...
@@ -381,6 +381,19 @@ describe Gitlab::Git::Repository, seed_helper: true do
}
}
])
])
end
end
it
'should not break on invalid syntax'
do
allow
(
repository
).
to
receive
(
:blob_content
).
and_return
(
<<-
GITMODULES
.
strip_heredoc
)
[submodule "six"]
path = six
url = git://github.com/randx/six.git
[submodule]
foo = bar
GITMODULES
expect
(
submodules
).
to
have_key
(
'six'
)
end
end
end
context
'where repo doesn\'t have submodules'
do
context
'where repo doesn\'t have submodules'
do
...
...
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