diff options
-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 a31ebe9cc87..d390184ecc6 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 d18a5c9dfa6..a231defbde2 100644 --- a/spec/models/commit_spec.rb +++ b/spec/models/commit_spec.rb @@ -475,4 +475,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 |