From 1cdc6c3a4ea28396788b2697f9cf257df161ff9a Mon Sep 17 00:00:00 2001 From: wxiaoguang Date: Sat, 23 Mar 2024 21:07:47 +0800 Subject: [PATCH 1/5] Escape paths for find file correctly (#30026) Fix #30020 --- routers/web/repo/find.go | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/routers/web/repo/find.go b/routers/web/repo/find.go index 07b372279882f..9da4237c1edd3 100644 --- a/routers/web/repo/find.go +++ b/routers/web/repo/find.go @@ -7,6 +7,7 @@ import ( "net/http" "code.gitea.io/gitea/modules/base" + "code.gitea.io/gitea/modules/util" "code.gitea.io/gitea/services/context" ) @@ -17,7 +18,7 @@ const ( // FindFiles render the page to find repository files func FindFiles(ctx *context.Context) { path := ctx.Params("*") - ctx.Data["TreeLink"] = ctx.Repo.RepoLink + "/src/" + path - ctx.Data["DataLink"] = ctx.Repo.RepoLink + "/tree-list/" + path + ctx.Data["TreeLink"] = ctx.Repo.RepoLink + "/src/" + util.PathEscapeSegments(path) + ctx.Data["DataLink"] = ctx.Repo.RepoLink + "/tree-list/" + util.PathEscapeSegments(path) ctx.HTML(http.StatusOK, tplFindFiles) } From b9c57fb78e8e0d80d786d8e1da433b6c7ebf2f1c Mon Sep 17 00:00:00 2001 From: 6543 <6543@obermui.de> Date: Sat, 23 Mar 2024 16:45:13 +0100 Subject: [PATCH 2/5] Determine fuzziness of bleve indexer by keyword length (#29706) also bleve did match on fuzzy search and the other way around. this also fix that bug. --- modules/indexer/code/bleve/bleve.go | 15 +++++++-------- modules/indexer/internal/bleve/query.go | 10 ++-------- modules/indexer/issues/bleve/bleve.go | 25 +++++++++++++------------ tests/integration/repo_search_test.go | 16 +++++++--------- 4 files changed, 29 insertions(+), 37 deletions(-) diff --git a/modules/indexer/code/bleve/bleve.go b/modules/indexer/code/bleve/bleve.go index d7f735e957db9..c607d780ef968 100644 --- a/modules/indexer/code/bleve/bleve.go +++ b/modules/indexer/code/bleve/bleve.go @@ -39,6 +39,8 @@ import ( const ( unicodeNormalizeName = "unicodeNormalize" maxBatchSize = 16 + // fuzzyDenominator determines the levenshtein distance per each character of a keyword + fuzzyDenominator = 4 ) func addUnicodeNormalizeTokenFilter(m *mapping.IndexMappingImpl) error { @@ -239,15 +241,12 @@ func (b *Indexer) Search(ctx context.Context, opts *internal.SearchOptions) (int keywordQuery query.Query ) + phraseQuery := bleve.NewMatchPhraseQuery(opts.Keyword) + phraseQuery.FieldVal = "Content" + phraseQuery.Analyzer = repoIndexerAnalyzer + keywordQuery = phraseQuery if opts.IsKeywordFuzzy { - phraseQuery := bleve.NewMatchPhraseQuery(opts.Keyword) - phraseQuery.FieldVal = "Content" - phraseQuery.Analyzer = repoIndexerAnalyzer - keywordQuery = phraseQuery - } else { - prefixQuery := bleve.NewPrefixQuery(opts.Keyword) - prefixQuery.FieldVal = "Content" - keywordQuery = prefixQuery + phraseQuery.Fuzziness = len(opts.Keyword) / fuzzyDenominator } if len(opts.RepoIDs) > 0 { diff --git a/modules/indexer/internal/bleve/query.go b/modules/indexer/internal/bleve/query.go index b96875343e5ea..21422b281c498 100644 --- a/modules/indexer/internal/bleve/query.go +++ b/modules/indexer/internal/bleve/query.go @@ -20,17 +20,11 @@ func NumericEqualityQuery(value int64, field string) *query.NumericRangeQuery { } // MatchPhraseQuery generates a match phrase query for the given phrase, field and analyzer -func MatchPhraseQuery(matchPhrase, field, analyzer string) *query.MatchPhraseQuery { +func MatchPhraseQuery(matchPhrase, field, analyzer string, fuzziness int) *query.MatchPhraseQuery { q := bleve.NewMatchPhraseQuery(matchPhrase) q.FieldVal = field q.Analyzer = analyzer - return q -} - -// PrefixQuery generates a match prefix query for the given prefix and field -func PrefixQuery(matchPrefix, field string) *query.PrefixQuery { - q := bleve.NewPrefixQuery(matchPrefix) - q.FieldVal = field + q.Fuzziness = fuzziness return q } diff --git a/modules/indexer/issues/bleve/bleve.go b/modules/indexer/issues/bleve/bleve.go index 927ad58cd4c57..1f54be721b37c 100644 --- a/modules/indexer/issues/bleve/bleve.go +++ b/modules/indexer/issues/bleve/bleve.go @@ -35,7 +35,11 @@ func addUnicodeNormalizeTokenFilter(m *mapping.IndexMappingImpl) error { }) } -const maxBatchSize = 16 +const ( + maxBatchSize = 16 + // fuzzyDenominator determines the levenshtein distance per each character of a keyword + fuzzyDenominator = 4 +) // IndexerData an update to the issue indexer type IndexerData internal.IndexerData @@ -156,19 +160,16 @@ func (b *Indexer) Search(ctx context.Context, options *internal.SearchOptions) ( var queries []query.Query if options.Keyword != "" { + fuzziness := 0 if options.IsFuzzyKeyword { - queries = append(queries, bleve.NewDisjunctionQuery([]query.Query{ - inner_bleve.MatchPhraseQuery(options.Keyword, "title", issueIndexerAnalyzer), - inner_bleve.MatchPhraseQuery(options.Keyword, "content", issueIndexerAnalyzer), - inner_bleve.MatchPhraseQuery(options.Keyword, "comments", issueIndexerAnalyzer), - }...)) - } else { - queries = append(queries, bleve.NewDisjunctionQuery([]query.Query{ - inner_bleve.PrefixQuery(options.Keyword, "title"), - inner_bleve.PrefixQuery(options.Keyword, "content"), - inner_bleve.PrefixQuery(options.Keyword, "comments"), - }...)) + fuzziness = len(options.Keyword) / fuzzyDenominator } + + queries = append(queries, bleve.NewDisjunctionQuery([]query.Query{ + inner_bleve.MatchPhraseQuery(options.Keyword, "title", issueIndexerAnalyzer, fuzziness), + inner_bleve.MatchPhraseQuery(options.Keyword, "content", issueIndexerAnalyzer, fuzziness), + inner_bleve.MatchPhraseQuery(options.Keyword, "comments", issueIndexerAnalyzer, fuzziness), + }...)) } if len(options.RepoIDs) > 0 || options.AllPublic { diff --git a/tests/integration/repo_search_test.go b/tests/integration/repo_search_test.go index cf199e98c2895..56cc45d9010e5 100644 --- a/tests/integration/repo_search_test.go +++ b/tests/integration/repo_search_test.go @@ -32,7 +32,7 @@ func TestSearchRepo(t *testing.T) { repo, err := repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user2", "repo1") assert.NoError(t, err) - executeIndexer(t, repo, code_indexer.UpdateRepoIndexer) + code_indexer.UpdateRepoIndexer(repo) testSearch(t, "/user2/repo1/search?q=Description&page=1", []string{"README.md"}) @@ -42,12 +42,14 @@ func TestSearchRepo(t *testing.T) { repo, err = repo_model.GetRepositoryByOwnerAndName(db.DefaultContext, "user2", "glob") assert.NoError(t, err) - executeIndexer(t, repo, code_indexer.UpdateRepoIndexer) + code_indexer.UpdateRepoIndexer(repo) testSearch(t, "/user2/glob/search?q=loren&page=1", []string{"a.txt"}) - testSearch(t, "/user2/glob/search?q=file3&page=1", []string{"x/b.txt"}) - testSearch(t, "/user2/glob/search?q=file4&page=1", []string{}) - testSearch(t, "/user2/glob/search?q=file5&page=1", []string{}) + testSearch(t, "/user2/glob/search?q=loren&page=1&t=match", []string{"a.txt"}) + testSearch(t, "/user2/glob/search?q=file3&page=1", []string{"x/b.txt", "a.txt"}) + testSearch(t, "/user2/glob/search?q=file3&page=1&t=match", []string{"x/b.txt", "a.txt"}) + testSearch(t, "/user2/glob/search?q=file4&page=1&t=match", []string{"x/b.txt", "a.txt"}) + testSearch(t, "/user2/glob/search?q=file5&page=1&t=match", []string{"x/b.txt", "a.txt"}) } func testSearch(t *testing.T, url string, expected []string) { @@ -57,7 +59,3 @@ func testSearch(t *testing.T, url string, expected []string) { filenames := resultFilenames(t, NewHTMLParser(t, resp.Body)) assert.EqualValues(t, expected, filenames) } - -func executeIndexer(t *testing.T, repo *repo_model.Repository, op func(*repo_model.Repository)) { - op(repo) -} From d9e33959b38d1463f69f6f8807bc50095cf6dbdb Mon Sep 17 00:00:00 2001 From: Yarden Shoham Date: Sat, 23 Mar 2024 20:18:45 +0200 Subject: [PATCH 3/5] Remove jQuery from the issue "go to" button (#30028) - Switched to plain JavaScript - Tested the "go to" button functionality and it works as before # Demo using JavaScript without jQuery ![demo](https://github.com/go-gitea/gitea/assets/20454870/76add18f-3294-4117-98b7-a97f576370e2) Signed-off-by: Yarden Shoham --- web_src/js/features/common-issue-list.js | 31 +++++++++++------------- 1 file changed, 14 insertions(+), 17 deletions(-) diff --git a/web_src/js/features/common-issue-list.js b/web_src/js/features/common-issue-list.js index 8182f99f29159..0c0f6c563d363 100644 --- a/web_src/js/features/common-issue-list.js +++ b/web_src/js/features/common-issue-list.js @@ -1,4 +1,3 @@ -import $ from 'jquery'; import {isElemHidden, onInputDebounce, submitEventSubmitter, toggleElem} from '../utils/dom.js'; import {GET} from '../modules/fetch.js'; @@ -30,42 +29,40 @@ export function parseIssueListQuickGotoLink(repoLink, searchText) { } export function initCommonIssueListQuickGoto() { - const $goto = $('#issue-list-quick-goto'); - if (!$goto.length) return; + const goto = document.getElementById('issue-list-quick-goto'); + if (!goto) return; - const $form = $goto.closest('form'); - const $input = $form.find('input[name=q]'); - const repoLink = $goto.attr('data-repo-link'); + const form = goto.closest('form'); + const input = form.querySelector('input[name=q]'); + const repoLink = goto.getAttribute('data-repo-link'); - $form.on('submit', (e) => { + form.addEventListener('submit', (e) => { // if there is no goto button, or the form is submitted by non-quick-goto elements, submit the form directly - let doQuickGoto = !isElemHidden($goto); + let doQuickGoto = !isElemHidden(goto); const submitter = submitEventSubmitter(e); - if (submitter !== $form[0] && submitter !== $input[0] && submitter !== $goto[0]) doQuickGoto = false; + if (submitter !== form && submitter !== input && submitter !== goto) doQuickGoto = false; if (!doQuickGoto) return; // if there is a goto button, use its link e.preventDefault(); - window.location.href = $goto.attr('data-issue-goto-link'); + window.location.href = goto.getAttribute('data-issue-goto-link'); }); const onInput = async () => { - const searchText = $input.val(); - + const searchText = input.value; // try to check whether the parsed goto link is valid let targetUrl = parseIssueListQuickGotoLink(repoLink, searchText); if (targetUrl) { const res = await GET(`${targetUrl}/info`); if (res.status !== 200) targetUrl = ''; } - // if the input value has changed, then ignore the result - if ($input.val() !== searchText) return; + if (input.value !== searchText) return; - toggleElem($goto, Boolean(targetUrl)); - $goto.attr('data-issue-goto-link', targetUrl); + toggleElem(goto, Boolean(targetUrl)); + goto.setAttribute('data-issue-goto-link', targetUrl); }; - $input.on('input', onInputDebounce(onInput)); + input.addEventListener('input', onInputDebounce(onInput)); onInput(); } From fabe01478ab449cc4870b7e2a9a1db3911bb14bd Mon Sep 17 00:00:00 2001 From: silverwind Date: Sat, 23 Mar 2024 19:45:11 +0100 Subject: [PATCH 4/5] Migrate font-weight helpers to tailwind (#30027) Commands ran: ```sh perl -p -i -e 's#gt-font-light#tw-font-light#g' web_src/js/**/* templates/**/* perl -p -i -e 's#gt-font-normal#tw-font-normal#g' web_src/js/**/* templates/**/* perl -p -i -e 's#gt-font-medium#tw-font-medium#g' web_src/js/**/* templates/**/* perl -p -i -e 's#gt-font-semibold#tw-font-semibold#g' web_src/js/**/* templates/**/* perl -p -i -e 's#gt-font-bold#tw-font-bold#g' web_src/js/**/* templates/**/* ``` --- tailwind.config.js | 7 +++++++ templates/repo/diff/box.tmpl | 2 +- templates/repo/diff/comments.tmpl | 2 +- templates/repo/header.tmpl | 2 +- templates/repo/issue/view_content.tmpl | 2 +- templates/repo/issue/view_content/comments.tmpl | 4 ++-- templates/repo/pulls/tab_menu.tmpl | 2 +- templates/repo/sub_menu.tmpl | 2 +- templates/shared/user/authorlink.tmpl | 2 +- templates/user/settings/account.tmpl | 2 +- web_src/css/helpers.css | 6 ------ web_src/js/components/DiffFileList.vue | 2 +- 12 files changed, 18 insertions(+), 17 deletions(-) diff --git a/tailwind.config.js b/tailwind.config.js index e2e8f23656263..01fc9ee24c539 100644 --- a/tailwind.config.js +++ b/tailwind.config.js @@ -66,5 +66,12 @@ export default { '3xl': '24px', 'full': 'var(--border-radius-circle)', // 50% }, + fontWeight: { + light: 'var(--font-weight-light)', + normal: 'var(--font-weight-normal)', + medium: 'var(--font-weight-medium)', + semibold: 'var(--font-weight-semibold)', + bold: 'var(--font-weight-bold)', + }, }, }; diff --git a/templates/repo/diff/box.tmpl b/templates/repo/diff/box.tmpl index 42eaf9d30ee4a..4ea1d2c621692 100644 --- a/templates/repo/diff/box.tmpl +++ b/templates/repo/diff/box.tmpl @@ -119,7 +119,7 @@ {{svg "octicon-chevron-down" 18}} {{end}} -
+
{{if $file.IsBin}} {{ctx.Locale.Tr "repo.diff.bin"}} diff --git a/templates/repo/diff/comments.tmpl b/templates/repo/diff/comments.tmpl index 4b626ba2b0a1b..070fe92317df2 100644 --- a/templates/repo/diff/comments.tmpl +++ b/templates/repo/diff/comments.tmpl @@ -11,7 +11,7 @@
{{if .OriginalAuthor}} - + {{svg (MigrationIcon $.root.Repository.GetOriginalURLHostname)}} {{.OriginalAuthor}} diff --git a/templates/repo/header.tmpl b/templates/repo/header.tmpl index 187a56bdccfb7..54f72943e4585 100644 --- a/templates/repo/header.tmpl +++ b/templates/repo/header.tmpl @@ -8,7 +8,7 @@
diff --git a/templates/repo/issue/view_content.tmpl b/templates/repo/issue/view_content.tmpl index 7966fc7e1c0fe..759de756629b5 100644 --- a/templates/repo/issue/view_content.tmpl +++ b/templates/repo/issue/view_content.tmpl @@ -23,7 +23,7 @@
{{if .Issue.OriginalAuthor}} - + {{svg (MigrationIcon .Repository.GetOriginalURLHostname)}} {{.Issue.OriginalAuthor}} diff --git a/templates/repo/issue/view_content/comments.tmpl b/templates/repo/issue/view_content/comments.tmpl index c0c4df925b7d0..b137dd0a9cba8 100644 --- a/templates/repo/issue/view_content/comments.tmpl +++ b/templates/repo/issue/view_content/comments.tmpl @@ -28,7 +28,7 @@
{{if .OriginalAuthor}} - + {{svg (MigrationIcon $.Repository.GetOriginalURLHostname)}} {{.OriginalAuthor}} @@ -411,7 +411,7 @@ {{end}} {{if .OriginalAuthor}} - + {{svg (MigrationIcon $.Repository.GetOriginalURLHostname)}} {{.OriginalAuthor}} diff --git a/templates/repo/pulls/tab_menu.tmpl b/templates/repo/pulls/tab_menu.tmpl index 2a653c7c695f5..7f4c460b8e193 100644 --- a/templates/repo/pulls/tab_menu.tmpl +++ b/templates/repo/pulls/tab_menu.tmpl @@ -15,7 +15,7 @@ {{ctx.Locale.Tr "repo.pulls.tab_files"}} {{if .NumFiles}}{{.NumFiles}}{{else}}-{{end}} - + {{if .Diff.TotalAddition}}+{{.Diff.TotalAddition}}{{end}} {{if .Diff.TotalDeletion}}-{{.Diff.TotalDeletion}}{{end}}
diff --git a/templates/repo/sub_menu.tmpl b/templates/repo/sub_menu.tmpl index 8edb0c151646a..654a65fa5ce30 100644 --- a/templates/repo/sub_menu.tmpl +++ b/templates/repo/sub_menu.tmpl @@ -25,7 +25,7 @@ {{range .LanguageStats}}
- + {{if eq .Language "other"}} {{ctx.Locale.Tr "repo.language_other"}} {{else}} diff --git a/templates/shared/user/authorlink.tmpl b/templates/shared/user/authorlink.tmpl index 64ccc62cd0115..4d8ad736be929 100644 --- a/templates/shared/user/authorlink.tmpl +++ b/templates/shared/user/authorlink.tmpl @@ -1 +1 @@ -{{.GetDisplayName}}{{if .IsBot}}bot{{end}} +{{.GetDisplayName}}{{if .IsBot}}bot{{end}} diff --git a/templates/user/settings/account.tmpl b/templates/user/settings/account.tmpl index efc09156e6f57..fb46dfbd2d0ac 100644 --- a/templates/user/settings/account.tmpl +++ b/templates/user/settings/account.tmpl @@ -136,7 +136,7 @@

{{svg "octicon-alert"}} {{ctx.Locale.Tr "settings.delete_prompt"}}

{{if .UserDeleteWithComments}} -

{{ctx.Locale.Tr "settings.delete_with_all_comments" .UserDeleteWithCommentsMaxTime}}

+

{{ctx.Locale.Tr "settings.delete_with_all_comments" .UserDeleteWithCommentsMaxTime}}

{{end}}
diff --git a/web_src/css/helpers.css b/web_src/css/helpers.css index c7097e631ba68..dd32c3fb31505 100644 --- a/web_src/css/helpers.css +++ b/web_src/css/helpers.css @@ -36,12 +36,6 @@ Gitea's private styles use `g-` prefix. text-overflow: ellipsis; } -.gt-font-light { font-weight: var(--font-weight-light) !important; } -.gt-font-normal { font-weight: var(--font-weight-normal) !important; } -.gt-font-medium { font-weight: var(--font-weight-medium) !important; } -.gt-font-semibold { font-weight: var(--font-weight-semibold) !important; } -.gt-font-bold { font-weight: var(--font-weight-bold) !important; } - .interact-fg { color: inherit !important; } .interact-fg:hover { color: var(--color-primary) !important; } .interact-fg:active { color: var(--color-primary-active) !important; } diff --git a/web_src/js/components/DiffFileList.vue b/web_src/js/components/DiffFileList.vue index 3a0e287808a64..66fe49c50bd2b 100644 --- a/web_src/js/components/DiffFileList.vue +++ b/web_src/js/components/DiffFileList.vue @@ -38,7 +38,7 @@ export default {