diff options
author | micael.bergeron <micaelbergeron@gmail.com> | 2017-11-15 09:12:04 -0500 |
---|---|---|
committer | micael.bergeron <micaelbergeron@gmail.com> | 2017-11-15 09:21:05 -0500 |
commit | 4374a38f0e8fbd856458a60f47083fb4d084d695 (patch) | |
tree | de063112d0909ac1c4fe0ad2c25f4466951a9abf | |
parent | a4072db0198896242886d22c644ed91c1016aa8d (diff) | |
download | gitlab-ce-4374a38f0e8fbd856458a60f47083fb4d084d695.tar.gz |
fix the commit reference pattern from matching other entities
-rw-r--r-- | app/models/commit.rb | 2 | ||||
-rw-r--r-- | changelogs/unreleased/39461-notes-api-for-issues-no-longer-returns-label-additions-removals.yml | 5 | ||||
-rw-r--r-- | spec/models/commit_spec.rb | 23 |
3 files changed, 29 insertions, 1 deletions
diff --git a/app/models/commit.rb b/app/models/commit.rb index 6dba154a6ea..e28bf28fab3 100644 --- a/app/models/commit.rb +++ b/app/models/commit.rb @@ -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 } diff --git a/changelogs/unreleased/39461-notes-api-for-issues-no-longer-returns-label-additions-removals.yml b/changelogs/unreleased/39461-notes-api-for-issues-no-longer-returns-label-additions-removals.yml new file mode 100644 index 00000000000..36c2f789eeb --- /dev/null +++ b/changelogs/unreleased/39461-notes-api-for-issues-no-longer-returns-label-additions-removals.yml @@ -0,0 +1,5 @@ +--- +title: Label addition/removal are not going to be redacted wrongfully in the API. +merge_request: 15080 +author: +type: fixed diff --git a/spec/models/commit_spec.rb b/spec/models/commit_spec.rb index e3cfa149e3a..3994eaba5d9 100644 --- a/spec/models/commit_spec.rb +++ b/spec/models/commit_spec.rb @@ -468,4 +468,27 @@ eos 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 |