loading up the forgejo repo on tangled to test page performance
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

fix: more permissive markup commit hash detection (#6784)

This allows many more variants of commit hashes to be detected and interpreted as link if they are enclosed by up to two different non-word/non-digit characters. I also had in mind RTL languages, where the question mark and similar symbols are on the left of the commit hash.

Resolves #6771

Reviewed-on: https://codeberg.org/forgejo/forgejo/pulls/6784
Reviewed-by: Earl Warren <earl-warren@noreply.codeberg.org>
Reviewed-by: Gusted <gusted@noreply.codeberg.org>
Co-authored-by: Robert Wolff <mahlzahn@posteo.de>
Co-committed-by: Robert Wolff <mahlzahn@posteo.de>

authored by

Robert Wolff
Robert Wolff
and committed by
Gusted
519169ee 499497c9

+17 -5
+5 -4
modules/markup/html.go
··· 1 1 // Copyright 2017 The Gitea Authors. All rights reserved. 2 + // Copyright 2025 The Forgejo Authors. 2 3 // SPDX-License-Identifier: MIT 3 4 4 5 package markup ··· 48 49 // hashCurrentPattern matches string that represents a commit SHA, e.g. d8a994ef243349f321568f9e36d5c3f444b99cae 49 50 // Although SHA1 hashes are 40 chars long, SHA256 are 64, the regex matches the hash from 7 to 64 chars in length 50 51 // so that abbreviated hash links can be used as well. This matches git and GitHub usability. 51 - hashCurrentPattern = regexp.MustCompile(`(?:\s|^|\(|\[)([0-9a-f]{7,64})(?:\s|$|\)|\]|[.,:](\s|$))`) 52 + hashCurrentPattern = regexp.MustCompile(`(?:^|\s)[^\w\d]{0,2}([0-9a-f]{7,64})[^\w\d]{0,2}(?:\s|$)`) 52 53 53 54 // shortLinkPattern matches short but difficult to parse [[name|link|arg=test]] syntax 54 55 shortLinkPattern = regexp.MustCompile(`\[\[(.*?)\]\](\w*)`) 55 56 56 - // anySHA1Pattern splits url containing SHA into parts 57 - anyHashPattern = regexp.MustCompile(`https?://(?:\S+/){4,5}([0-9a-f]{40,64})(/[-+~_%.a-zA-Z0-9/]+)?(\?[-+~_%\.a-zA-Z0-9=&]+)?(#[-+~_%.a-zA-Z0-9]+)?`) 57 + // anyHashPattern splits url containing SHA into parts 58 + anyHashPattern = regexp.MustCompile(`https?://(?:\S+/){4,5}([0-9a-f]{7,64})(/[-+~_%.a-zA-Z0-9/]+)?(\?[-+~_%\.a-zA-Z0-9=&]+)?(#[-+~_%.a-zA-Z0-9]+)?`) 58 59 59 60 // comparePattern matches "http://domain/org/repo/compare/COMMIT1...COMMIT2#hash" 60 61 comparePattern = regexp.MustCompile(`https?://(?:\S+/){4,5}([0-9a-f]{7,64})(\.\.\.?)([0-9a-f]{7,64})?(#[-+~_%.a-zA-Z0-9]+)?`) ··· 1174 1175 } 1175 1176 } 1176 1177 1177 - // hashCurrentPatternProcessor renders SHA1 strings to corresponding links that 1178 + // hashCurrentPatternProcessor renders SHA1/SHA256 strings to corresponding links that 1178 1179 // are assumed to be in the same repository. 1179 1180 func hashCurrentPatternProcessor(ctx *RenderContext, node *html.Node) { 1180 1181 if ctx.Metas == nil || ctx.Metas["user"] == "" || ctx.Metas["repo"] == "" || ctx.Metas["repoPath"] == "" {
+11 -1
modules/markup/html_internal_test.go
··· 1 1 // Copyright 2018 The Gitea Authors. All rights reserved. 2 + // Copyright 2025 The Forgejo Authors. 2 3 // SPDX-License-Identifier: MIT 3 4 4 5 package markup ··· 391 392 `<a href="http://localhost:3000/testOrg/testOrgRepo/pulls/2/commits" class="ref-issue">testOrg/testOrgRepo#2/commits</a>`) 392 393 } 393 394 394 - func TestRegExp_sha1CurrentPattern(t *testing.T) { 395 + func TestRegExp_hashCurrentPattern(t *testing.T) { 395 396 trueTestCases := []string{ 396 397 "d8a994ef243349f321568f9e36d5c3f444b99cae", 397 398 "abcdefabcdefabcdefabcdefabcdefabcdefabcd", ··· 399 400 "[abcdefabcdefabcdefabcdefabcdefabcdefabcd]", 400 401 "abcdefabcdefabcdefabcdefabcdefabcdefabcd.", 401 402 "abcdefabcdefabcdefabcdefabcdefabcdefabcd:", 403 + "d8a994ef243349f321568f9e36d5c3f444b99cae12424fa123391042fbae2319", 404 + "abcdefd?", 405 + "abcdefd!", 406 + "!abcd3ef", 407 + ":abcd3ef", 408 + ".abcd3ef", 409 + " (abcd3ef). ", 402 410 } 403 411 falseTestCases := []string{ 404 412 "test", ··· 406 414 "e59ff077-2d03-4e6b-964d-63fbaea81f", 407 415 "abcdefghijklmnopqrstuvwxyzabcdefghijklmn", 408 416 "abcdefghijklmnopqrstuvwxyzabcdefghijklmO", 417 + "commit/abcdefd", 418 + "abcd3ef...defabcd", 409 419 } 410 420 411 421 for _, testCase := range trueTestCases {
+1
modules/markup/html_test.go
··· 1 1 // Copyright 2017 The Gitea Authors. All rights reserved. 2 + // Copyright 2025 The Forgejo Authors. 2 3 // SPDX-License-Identifier: MIT 3 4 4 5 package markup_test