Skip to content

Commit

Permalink
Replace special symbols by _ rune.
Browse files Browse the repository at this point in the history
  • Loading branch information
ice-myles committed Feb 14, 2025
1 parent def64ef commit bdefce7
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 11 deletions.
2 changes: 1 addition & 1 deletion database/query/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func init() {
},
{
Name: "subzero_nostr_replace_special_chars",
Ptr: subzeroNostrRemoveSpecialChars,
Ptr: subzeroNostrReplaceSpecialChars,
Pure: true,
},
}
Expand Down
10 changes: 5 additions & 5 deletions database/query/client_functions.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}
Expand Down Expand Up @@ -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)
}
2 changes: 1 addition & 1 deletion database/query/query_text_search.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
8 changes: 4 additions & 4 deletions database/query/query_where_builder.go
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
}

0 comments on commit bdefce7

Please sign in to comment.