[PR #2143] [MERGED] Fix SHA1 hash linking #16256

Closed
opened 2025-11-02 12:06:04 -06:00 by GiteaMirror · 0 comments
Owner

📋 Pull Request Information

Original PR: https://github.com/go-gitea/gitea/pull/2143
Author: @rsmarples
Created: 7/11/2017
Status: Merged
Merged: 7/12/2017
Merged by: @bkcsoft

Base: masterHead: fix-commit-linking


📝 Commits (2)

  • 55c8438 Match abbreviated SHA1 hash to link to
  • 6a70c83 Add tests for hashs of length 7 and 39 characters

📊 Changes

2 files changed (+15 additions, -6 deletions)

View changed files

📝 modules/markdown/markdown.go (+13 -6)
📝 modules/markdown/markdown_test.go (+2 -0)

📄 Description

This changes the regex to look for a hash from 7 to 40 characters,
to match the use of abbreviated hash lookups in both git and github.
The restriction of not being a pure number is also removed because
1234567 is now considered a valid abbreviated hash, as is deadbeef.

A note has been added to the top of the code to state that the
literal regex match is fine, but no extra validation is currently
performed so some false positives are expected.

A future change could ensure that the hash exists in the repository
before rendering it as a link, although this might incur a slight
performance penalty.

Reverts part of commit 4a46613 and fixes #2053.


🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.

## 📋 Pull Request Information **Original PR:** https://github.com/go-gitea/gitea/pull/2143 **Author:** [@rsmarples](https://github.com/rsmarples) **Created:** 7/11/2017 **Status:** ✅ Merged **Merged:** 7/12/2017 **Merged by:** [@bkcsoft](https://github.com/bkcsoft) **Base:** `master` ← **Head:** `fix-commit-linking` --- ### 📝 Commits (2) - [`55c8438`](https://github.com/go-gitea/gitea/commit/55c84382f2416c2eb00265e55dfbaccb72907976) Match abbreviated SHA1 hash to link to - [`6a70c83`](https://github.com/go-gitea/gitea/commit/6a70c8355b705daa883692323b8d03a269094f1f) Add tests for hashs of length 7 and 39 characters ### 📊 Changes **2 files changed** (+15 additions, -6 deletions) <details> <summary>View changed files</summary> 📝 `modules/markdown/markdown.go` (+13 -6) 📝 `modules/markdown/markdown_test.go` (+2 -0) </details> ### 📄 Description This changes the regex to look for a hash from 7 to 40 characters, to match the use of abbreviated hash lookups in both git and github. The restriction of not being a pure number is also removed because 1234567 is now considered a valid abbreviated hash, as is deadbeef. A note has been added to the top of the code to state that the literal regex match is fine, but no extra validation is currently performed so some false positives are expected. A future change could ensure that the hash exists in the repository before rendering it as a link, although this might incur a slight performance penalty. Reverts part of commit 4a46613 and fixes #2053. --- <sub>🔄 This issue represents a GitHub Pull Request. It cannot be merged through Gitea due to API limitations.</sub>
GiteaMirror added the pull-request label 2025-11-02 12:06:04 -06:00
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: github-starred/gitea#16256