Read about our upcoming Code of Conduct on this issue

Commit 4374a38f authored by micael.bergeron's avatar micael.bergeron
Browse files

fix the commit reference pattern from matching other entities

parent 431ae0705844
......@@ -26,7 +26,7 @@ class Commit
DIFF_HARD_LIMIT_LINES = 50000
MIN_SHA_LENGTH = 7
COMMIT_SHA_PATTERN = /\h{#{MIN_SHA_LENGTH},40}/.freeze
COMMIT_SHA_PATTERN = /\b(?<![~#!@:])\h{#{MIN_SHA_LENGTH},40}/.freeze
def banzai_render_context(field)
context = { pipeline: :single_line, project: self.project }
......
---
title: Label addition/removal are not going to be redacted wrongfully in the API.
merge_request: 15080
author:
type: fixed
......@@ -468,4 +468,27 @@
expect(described_class.valid_hash?('a' * 41)).to be false
end
end
describe '.reference_pattern' do
where(:ref, :matches?) do
sha = Digest::SHA1.hexdigest 'thisisacommitid'
[
[sha.first(Commit::MIN_SHA_LENGTH - 1), false],
[sha.first(Commit::MIN_SHA_LENGTH), true],
[sha, true],
['~' << sha, false], # labels
['!' << sha, false], # merge_request
[':' << sha, false], # emoji
['#' << sha, false], # issue
['@' << sha, false], # user
]
end
with_them do
it "should match only on commit references" do
expect(Commit.reference_pattern.match(ref).present?).to eq(matches?)
end
end
end
end
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment