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
d9774257
Commit
d9774257
authored
Jan 29, 2016
by
Robert Speicher
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Increase the minimum length for commit SHA matching to 7
This is the git default and will help to prevent false positive matches. Closes #12706
parent
dec21517
Hide whitespace changes
Inline
Side-by-side
Showing
6 changed files
with
14 additions
and
14 deletions
+14
-14
commit.rb
app/models/commit.rb
+3
-3
commit_range.rb
app/models/commit_range.rb
+2
-2
routes.rb
config/routes.rb
+1
-1
commit_reference_filter_spec.rb
spec/lib/banzai/filter/commit_reference_filter_spec.rb
+2
-2
project_routing_spec.rb
spec/routing/project_routing_spec.rb
+4
-4
filter_spec_helper.rb
spec/support/filter_spec_helper.rb
+2
-2
No files found.
app/models/commit.rb
View file @
d9774257
...
...
@@ -68,18 +68,18 @@ class Commit
# Pattern used to extract commit references from text
#
# The SHA can be between
6
and 40 hex characters.
# The SHA can be between
7
and 40 hex characters.
#
# This pattern supports cross-project references.
def
self
.
reference_pattern
%r{
(?:
#{
Project
.
reference_pattern
}#{
reference_prefix
}
)?
(?<commit>
\h
{
6
,40})
(?<commit>
\h
{
7
,40})
}x
end
def
self
.
link_reference_pattern
super
(
"commit"
,
/(?<commit>\h{
6
,40})/
)
super
(
"commit"
,
/(?<commit>\h{
7
,40})/
)
end
def
to_reference
(
from_project
=
nil
)
...
...
app/models/commit_range.rb
View file @
d9774257
...
...
@@ -32,8 +32,8 @@ class CommitRange
PATTERN
=
/
#{
REF_PATTERN
}
\.{2,3}
#{
REF_PATTERN
}
/
# In text references, the beginning and ending refs can only be SHAs
# between
6
and 40 hex characters.
STRICT_PATTERN
=
/\h{
6,40}\.{2,3}\h{6
,40}/
# between
7
and 40 hex characters.
STRICT_PATTERN
=
/\h{
7,40}\.{2,3}\h{7
,40}/
def
self
.
reference_prefix
'@'
...
...
config/routes.rb
View file @
d9774257
...
...
@@ -490,7 +490,7 @@ Rails.application.routes.draw do
end
resource
:avatar
,
only:
[
:show
,
:destroy
]
resources
:commit
,
only:
[
:show
],
constraints:
{
id:
/
[[:alnum:]]{6
,40}/
}
do
resources
:commit
,
only:
[
:show
],
constraints:
{
id:
/
\h{7
,40}/
}
do
member
do
get
:branches
get
:builds
...
...
spec/lib/banzai/filter/commit_reference_filter_spec.rb
View file @
d9774257
...
...
@@ -21,7 +21,7 @@ describe Banzai::Filter::CommitReferenceFilter, lib: true do
let
(
:reference
)
{
commit
.
id
}
# Let's test a variety of commit SHA sizes just to be paranoid
[
6
,
8
,
12
,
18
,
20
,
32
,
40
].
each
do
|
size
|
[
7
,
8
,
12
,
18
,
20
,
32
,
40
].
each
do
|
size
|
it
"links to a valid reference of
#{
size
}
characters"
do
doc
=
reference_filter
(
"See
#{
reference
[
0
...
size
]
}
"
)
...
...
@@ -35,7 +35,7 @@ describe Banzai::Filter::CommitReferenceFilter, lib: true do
doc
=
reference_filter
(
"See
#{
commit
.
id
}
"
)
expect
(
doc
.
text
).
to
eq
"See
#{
commit
.
short_id
}
"
doc
=
reference_filter
(
"See
#{
commit
.
id
[
0
...
6
]
}
"
)
doc
=
reference_filter
(
"See
#{
commit
.
id
[
0
...
7
]
}
"
)
expect
(
doc
.
text
).
to
eq
"See
#{
commit
.
short_id
}
"
end
...
...
spec/routing/project_routing_spec.rb
View file @
d9774257
...
...
@@ -321,12 +321,12 @@ describe Projects::HooksController, 'routing' do
end
end
# project_commit GET /:project_id/commit/:id(.:format) commit#show {id: /
[[:alnum:]]{6
,40}/, project_id: /[^\/]+/}
# project_commit GET /:project_id/commit/:id(.:format) commit#show {id: /
\h{7
,40}/, project_id: /[^\/]+/}
describe
Projects
::
CommitController
,
'routing'
do
it
'to #show'
do
expect
(
get
(
'/gitlab/gitlabhq/commit/4246fb
'
)).
to
route_to
(
'projects/commit#show'
,
namespace_id:
'gitlab'
,
project_id:
'gitlabhq'
,
id:
'4246fb
'
)
expect
(
get
(
'/gitlab/gitlabhq/commit/4246fb
.diff'
)).
to
route_to
(
'projects/commit#show'
,
namespace_id:
'gitlab'
,
project_id:
'gitlabhq'
,
id:
'4246fb
'
,
format:
'diff'
)
expect
(
get
(
'/gitlab/gitlabhq/commit/4246fb
.patch'
)).
to
route_to
(
'projects/commit#show'
,
namespace_id:
'gitlab'
,
project_id:
'gitlabhq'
,
id:
'4246fb
'
,
format:
'patch'
)
expect
(
get
(
'/gitlab/gitlabhq/commit/4246fb
d'
)).
to
route_to
(
'projects/commit#show'
,
namespace_id:
'gitlab'
,
project_id:
'gitlabhq'
,
id:
'4246fbd
'
)
expect
(
get
(
'/gitlab/gitlabhq/commit/4246fb
d.diff'
)).
to
route_to
(
'projects/commit#show'
,
namespace_id:
'gitlab'
,
project_id:
'gitlabhq'
,
id:
'4246fbd
'
,
format:
'diff'
)
expect
(
get
(
'/gitlab/gitlabhq/commit/4246fb
d.patch'
)).
to
route_to
(
'projects/commit#show'
,
namespace_id:
'gitlab'
,
project_id:
'gitlabhq'
,
id:
'4246fbd
'
,
format:
'patch'
)
expect
(
get
(
'/gitlab/gitlabhq/commit/4246fbd13872934f72a8fd0d6fb1317b47b59cb5'
)).
to
route_to
(
'projects/commit#show'
,
namespace_id:
'gitlab'
,
project_id:
'gitlabhq'
,
id:
'4246fbd13872934f72a8fd0d6fb1317b47b59cb5'
)
end
end
...
...
spec/support/filter_spec_helper.rb
View file @
d9774257
...
...
@@ -67,9 +67,9 @@ module FilterSpecHelper
if
reference
=~
/\A(.+)?.\d+\z/
# Integer-based reference with optional project prefix
reference
.
gsub
(
/\d+\z/
)
{
|
i
|
i
.
to_i
+
1
}
elsif
reference
=~
/\A(.+@)?(\h{
6
,40}\z)/
elsif
reference
=~
/\A(.+@)?(\h{
7
,40}\z)/
# SHA-based reference with optional prefix
reference
.
gsub
(
/\h{
6
,40}\z/
)
{
|
v
|
v
.
reverse
}
reference
.
gsub
(
/\h{
7
,40}\z/
)
{
|
v
|
v
.
reverse
}
else
reference
.
gsub
(
/\w+\z/
)
{
|
v
|
v
.
reverse
}
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