Stopped removing *s from the end of search phrases

This commit is contained in:
Harrison Healey
2016-03-03 15:20:26 -05:00
parent d1b1148ea8
commit cd4172bfd8
3 changed files with 7 additions and 2 deletions

View File

@@ -89,9 +89,9 @@ func parseSearchFlags(input []string) ([]string, [][2]string) {
}
if !isFlag {
// trim off surrounding punctuation
// trim off surrounding punctuation (note that we leave trailing asterisks to allow wildcards)
word = puncStart.ReplaceAllString(word, "")
word = puncEnd.ReplaceAllString(word, "")
word = puncEndWildcard.ReplaceAllString(word, "")
// and remove extra pound #s
word = hashtagStart.ReplaceAllString(word, "#")

View File

@@ -216,4 +216,8 @@ func TestParseSearchParams(t *testing.T) {
if sp := ParseSearchParams("##hashtag +#plus+"); len(sp) != 1 || sp[0].Terms != "#hashtag #plus" || sp[0].IsHashtag != true || len(sp[0].InChannels) != 0 || len(sp[0].FromUsers) != 0 {
t.Fatalf("Incorrect output from parse search params: %v", sp[0])
}
if sp := ParseSearchParams("wildcar*"); len(sp) != 1 || sp[0].Terms != "wildcar*" || sp[0].IsHashtag != false || len(sp[0].InChannels) != 0 || len(sp[0].FromUsers) != 0 {
t.Fatalf("Incorrect output from parse search params: %v", sp[0])
}
}

View File

@@ -291,6 +291,7 @@ var validHashtag = regexp.MustCompile(`^(#[A-Za-zäöüÄÖÜß]+[A-Za-z0-9äö
var puncStart = regexp.MustCompile(`^[.,()&$!\?\[\]{}':;\\<>\-+=%^*|]+`)
var hashtagStart = regexp.MustCompile(`^#{2,}`)
var puncEnd = regexp.MustCompile(`[.,()&$#!\?\[\]{}':;\\<>\-+=%^*|]+$`)
var puncEndWildcard = regexp.MustCompile(`[.,()&$#!\?\[\]{}':;\\<>\-+=%^|]+$`)
func ParseHashtags(text string) (string, string) {
words := strings.Fields(text)