[PR #2293] [MERGED] Fix SHA1 hash linking (#2143) #16328

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

📋 Pull Request Information

Original PR: https://github.com/go-gitea/gitea/pull/2293
Author: @lunny
Created: 8/11/2017
Status: Merged
Merged: 8/12/2017
Merged by: @lunny

Base: release/v1.1Head: lunny/backport_2143


📝 Commits (1)

📊 Changes

2 files changed (+18 additions, -9 deletions)

View changed files

📝 modules/markdown/markdown.go (+16 -9)
📝 modules/markdown/markdown_test.go (+2 -0)

📄 Description

Back port from #2143.

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/2293 **Author:** [@lunny](https://github.com/lunny) **Created:** 8/11/2017 **Status:** ✅ Merged **Merged:** 8/12/2017 **Merged by:** [@lunny](https://github.com/lunny) **Base:** `release/v1.1` ← **Head:** `lunny/backport_2143` --- ### 📝 Commits (1) - [`c8a5adb`](https://github.com/go-gitea/gitea/commit/c8a5adbccfb13512ee4f209d6c8a0930bb8bf0a4) Fix SHA1 hash linking (#2143) ### 📊 Changes **2 files changed** (+18 additions, -9 deletions) <details> <summary>View changed files</summary> 📝 `modules/markdown/markdown.go` (+16 -9) 📝 `modules/markdown/markdown_test.go` (+2 -0) </details> ### 📄 Description Back port from #2143. 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:07:55 -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#16328