Skip to content
Snippets Groups Projects
Commit 9fc95766 authored by Paul Slaughter's avatar Paul Slaughter :two:
Browse files

Fix commit markdown parsing with word boundaries

- Previously we would match the cceededc in something
  like succeededc.
- #450246

Changelog: fixed
parent e5815c8a
No related branches found
No related tags found
1 merge request!147185Fix commit markdown parsing with word boundaries
Pipeline #1214265089 passed with warnings
Pipeline: GitLab

#1214272647

    Pipeline: GitLab

    #1214270427

      Pipeline: GitLab

      #1214270382

        ......@@ -31,6 +31,7 @@ class Commit
        MIN_SHA_LENGTH = Gitlab::Git::Commit::MIN_SHA_LENGTH
        MAX_SHA_LENGTH = Gitlab::Git::Commit::MAX_SHA_LENGTH
        COMMIT_SHA_PATTERN = Gitlab::Git::Commit::SHA_PATTERN
        WHOLE_WORD_COMMIT_SHA_PATTERN = /\b#{COMMIT_SHA_PATTERN}\b/
        EXACT_COMMIT_SHA_PATTERN = /\A#{COMMIT_SHA_PATTERN}\z/
        # Used by GFM to match and present link extensions on node texts and hrefs.
        LINK_EXTENSION_PATTERN = /(patch)/
        ......@@ -205,7 +206,7 @@ def self.reference_valid?(reference)
        def self.reference_pattern
        @reference_pattern ||= %r{
        (?:#{Project.reference_pattern}#{reference_prefix})?
        (?<commit>#{COMMIT_SHA_PATTERN})
        (?<commit>#{WHOLE_WORD_COMMIT_SHA_PATTERN})
        }x
        end
        ......
        ......@@ -33,6 +33,20 @@
        end
        end
        # This solves https://gitlab.com/gitlab-org/gitlab/-/issues/450246
        it "does not render link when reference is ending a word" do
        doc = reference_filter("Hello Wo#{reference[0...7]}")
        expect(doc.css('a')).to be_empty
        end
        # This solves https://gitlab.com/gitlab-org/gitlab/-/issues/450246
        it "does not render link when reference is starting a word" do
        doc = reference_filter("Hello #{reference[0...7]}ld")
        expect(doc.css('a')).to be_empty
        end
        it 'always uses the short ID as the link text' do
        doc = reference_filter("See #{commit.id}")
        expect(doc.text).to eq "See #{commit.short_id}"
        ......
        0% Loading or .
        You are about to add 0 people to the discussion. Proceed with caution.
        Finish editing this message first!
        Please register or to comment