From bdefce7e39e0961b97ff99f6647a54f590356f94 Mon Sep 17 00:00:00 2001 From: ice-myles <96409608+ice-myles@users.noreply.github.com> Date: Fri, 14 Feb 2025 16:18:30 +0300 Subject: [PATCH] Replace special symbols by _ rune. --- database/query/client.go | 2 +- database/query/client_functions.go | 10 +++++----- database/query/query_text_search.go | 2 +- database/query/query_where_builder.go | 8 ++++---- 4 files changed, 11 insertions(+), 11 deletions(-) diff --git a/database/query/client.go b/database/query/client.go index 621a0a3..c0e4357 100644 --- a/database/query/client.go +++ b/database/query/client.go @@ -85,7 +85,7 @@ func init() { }, { Name: "subzero_nostr_replace_special_chars", - Ptr: subzeroNostrRemoveSpecialChars, + Ptr: subzeroNostrReplaceSpecialChars, Pure: true, }, } diff --git a/database/query/client_functions.go b/database/query/client_functions.go index cfc0f30..70a2a70 100644 --- a/database/query/client_functions.go +++ b/database/query/client_functions.go @@ -101,21 +101,21 @@ func sqlGetEventAddress(eventID string, kind int, masterPubkey, dTag string) str func sqlGenerateContentMetadata(eventKind int, content string, jsonTags string) (string, error) { switch eventKind { case nostr.KindProfileMetadata: - return removeSpecialChars(parseProfileContentMetadata(content)), nil + return replaceSpecialChars(parseProfileContentMetadata(content)), nil case nostr.KindTextNote, nostr.KindArticle, model.CustomIONKindEditableTextNote: var tags model.Tags if err := tags.Scan(jsonTags); err != nil { return "", errors.Wrap(err, "failed to unmarshal tags") } - return removeSpecialChars(processIMetaTags(tags)), nil + return replaceSpecialChars(processIMetaTags(tags)), nil case nostr.KindFileMetadata: var tags model.Tags if err := tags.Scan(jsonTags); err != nil { return "", errors.Wrap(err, "failed to unmarshal tags") } - return removeSpecialChars(processAltSummaryTags(tags)), nil + return replaceSpecialChars(processAltSummaryTags(tags)), nil default: return "", nil } @@ -150,6 +150,6 @@ func processAltSummaryTags(tags model.Tags) string { return strings.Join(metadata, " ") } -func subzeroNostrRemoveSpecialChars(value string) string { - return removeSpecialChars(value) +func subzeroNostrReplaceSpecialChars(value string) string { + return replaceSpecialChars(value) } diff --git a/database/query/query_text_search.go b/database/query/query_text_search.go index 35f2a6b..4d12dfe 100644 --- a/database/query/query_text_search.go +++ b/database/query/query_text_search.go @@ -29,7 +29,7 @@ func parseContentMetadata(ev *model.Event) string { content = strings.Join(values, " ") } - return removeSpecialChars(content) + return replaceSpecialChars(content) } func extractFTS5IMeta(tags []model.Tag) []string { diff --git a/database/query/query_where_builder.go b/database/query/query_where_builder.go index c185673..c438c12 100644 --- a/database/query/query_where_builder.go +++ b/database/query/query_where_builder.go @@ -782,7 +782,7 @@ func (w *whereBuilder) Build(filters ...model.Filter) (sql string, params map[st w.Dependencies = append(w.Dependencies, dbFilter.Dependencies...) } if w.Prefix != "" && dbFilter.SearchText != "" { - searchKeywords = append(searchKeywords, removeSpecialChars(dbFilter.SearchText)+"*") + searchKeywords = append(searchKeywords, replaceSpecialChars(dbFilter.SearchText)+"*") } } if w.Prefix != "" && len(searchKeywords) > 0 { @@ -1001,16 +1001,16 @@ func (w *whereBuilder) BuildForPrecalculatedCounters(filters ...model.Filter) (s return w.String(), w.Params, nil } -func removeSpecialChars(input string) string { +func replaceSpecialChars(input string) string { if input == "" { return "" } return strings.Map(func(r rune) rune { - if unicode.IsLetter(r) || unicode.IsDigit(r) || unicode.IsSpace(r) { + if unicode.IsLetter(r) || unicode.IsDigit(r) || unicode.IsSpace(r) || unicode.IsSymbol('_') { return r } - return -1 + return '_' }, input) }