Skip to content

Commit

Permalink
Replace problematic chars in tsvector (#103)
Browse files Browse the repository at this point in the history
  • Loading branch information
mgdigital authored Jan 13, 2024
1 parent 01b1448 commit d999b4c
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 2 deletions.
6 changes: 5 additions & 1 deletion internal/database/fts/tokenizer.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,11 @@ func (l *tokenizerLexer) readPhrase() []string {
if tb, ok := table.Tables[section]; ok {
if len(tb) > int(position) {
subst := tb[position]
appendStr(strings.TrimSpace(subst))
// replace some problematic characters
subst = strings.ReplaceAll(subst, "'", "_sq_")
subst = strings.ReplaceAll(subst, "\\", "_bs_")
subst = strings.TrimSpace(subst)
appendStr(subst)
if isNonBreakingLang || len(subst) == 0 || subst[len(subst)-1] == ' ' {
breakWord()
}
Expand Down
2 changes: 1 addition & 1 deletion internal/database/fts/tsvector.go
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ var nonWordChar = regexp.MustCompile(`\W`)

func quoteLexeme(str string, force bool) string {
if force || nonWordChar.MatchString(str) {
str = "'" + strings.Replace(str, "'", "''", -1) + "'"
str = "'" + strings.ReplaceAll(str, "'", "''") + "'"
}
return str
}
Expand Down

0 comments on commit d999b4c

Please sign in to comment.