diff options
author | Harrison Healey <harrisonmhealey@gmail.com> | 2016-06-01 16:05:36 -0400 |
---|---|---|
committer | Corey Hulen <corey@hulen.com> | 2016-06-01 13:05:36 -0700 |
commit | 2ea54b9d1e382db8eeb4254dc637e7d04316d01e (patch) | |
tree | 7ddf3586979f6582e578d933b6c7820776f5b8e3 /model/search_params.go | |
parent | 3ce6dfc71eb8f1bf2e9f2d860cf086424cf1c46d (diff) | |
download | chat-2ea54b9d1e382db8eeb4254dc637e7d04316d01e.tar.gz chat-2ea54b9d1e382db8eeb4254dc637e7d04316d01e.tar.bz2 chat-2ea54b9d1e382db8eeb4254dc637e7d04316d01e.zip |
PLT-2283 Improved trimming of punctuation from hashtags and search terms (#3178)
* Improved trimming of punctuation from hashtags and search terms
* Separated punctuation regexes used for hashtags and for search terms
Diffstat (limited to 'model/search_params.go')
-rw-r--r-- | model/search_params.go | 8 |
1 files changed, 6 insertions, 2 deletions
diff --git a/model/search_params.go b/model/search_params.go index 250c8e1f3..1772c9028 100644 --- a/model/search_params.go +++ b/model/search_params.go @@ -4,9 +4,13 @@ package model import ( + "regexp" "strings" ) +var searchTermPuncStart = regexp.MustCompile(`^[^\pL\d\s#"]+`) +var searchTermPuncEnd = regexp.MustCompile(`[^\pL\d\s*"]+$`) + type SearchParams struct { Terms string IsHashtag bool @@ -91,8 +95,8 @@ func parseSearchFlags(input []string) ([]string, [][2]string) { if !isFlag { // trim off surrounding punctuation (note that we leave trailing asterisks to allow wildcards) - word = puncStart.ReplaceAllString(word, "") - word = puncEndWildcard.ReplaceAllString(word, "") + word = searchTermPuncStart.ReplaceAllString(word, "") + word = searchTermPuncEnd.ReplaceAllString(word, "") // and remove extra pound #s word = hashtagStart.ReplaceAllString(word, "#") |