From 97ede2a428faf3a62ce0140e51ed591e261c09a1 Mon Sep 17 00:00:00 2001 From: hmhealey Date: Mon, 25 Jan 2016 16:47:49 -0500 Subject: Updated serverside hashtag regex to ignore more punctuation around words --- model/search_params.go | 18 +++++++++++------- model/search_params_test.go | 10 +++++++--- model/utils.go | 10 ++++++++-- model/utils_test.go | 41 ++++++++++++++++++++++++++++------------- 4 files changed, 54 insertions(+), 25 deletions(-) (limited to 'model') diff --git a/model/search_params.go b/model/search_params.go index 17a64d980..9a7406a07 100644 --- a/model/search_params.go +++ b/model/search_params.go @@ -20,12 +20,7 @@ func splitWordsNoQuotes(text string) []string { words := []string{} for _, word := range strings.Fields(text) { - word = puncStart.ReplaceAllString(word, "") - word = puncEnd.ReplaceAllString(word, "") - - if len(word) != 0 { - words = append(words, word) - } + words = append(words, word) } return words @@ -94,7 +89,16 @@ func parseSearchFlags(input []string) ([]string, [][2]string) { } if !isFlag { - words = append(words, word) + // trim off surrounding punctuation + word = puncStart.ReplaceAllString(word, "") + word = puncEnd.ReplaceAllString(word, "") + + // and remove extra pound #s + word = hashtagStart.ReplaceAllString(word, "#") + + if len(word) != 0 { + words = append(words, word) + } } } diff --git a/model/search_params_test.go b/model/search_params_test.go index af4cbe595..59eb0a113 100644 --- a/model/search_params_test.go +++ b/model/search_params_test.go @@ -118,19 +118,19 @@ func TestParseSearchFlags(t *testing.T) { t.Fatalf("got incorrect flags %v", flags) } - if words, flags := parseSearchFlags(splitWords("fruit: cherry")); len(words) != 2 || words[0] != "fruit:" || words[1] != "cherry" { + if words, flags := parseSearchFlags(splitWords("fruit: cherry")); len(words) != 2 || words[0] != "fruit" || words[1] != "cherry" { t.Fatalf("got incorrect words %v", words) } else if len(flags) != 0 { t.Fatalf("got incorrect flags %v", flags) } - if words, flags := parseSearchFlags(splitWords("channel:")); len(words) != 1 || words[0] != "channel:" { + if words, flags := parseSearchFlags(splitWords("channel:")); len(words) != 1 || words[0] != "channel" { t.Fatalf("got incorrect words %v", words) } else if len(flags) != 0 { t.Fatalf("got incorrect flags %v", flags) } - if words, flags := parseSearchFlags(splitWords("channel: first in: second from:")); len(words) != 1 || words[0] != "from:" { + if words, flags := parseSearchFlags(splitWords("channel: first in: second from:")); len(words) != 1 || words[0] != "from" { t.Fatalf("got incorrect words %v", words) } else if len(flags) != 2 || flags[0][0] != "channel" || flags[0][1] != "first" || flags[1][0] != "in" || flags[1][1] != "second" { t.Fatalf("got incorrect flags %v", flags) @@ -212,4 +212,8 @@ func TestParseSearchParams(t *testing.T) { if sp := ParseSearchParams("testing in:channel from:someone"); len(sp) != 1 || sp[0].Terms != "testing" || len(sp[0].InChannels) != 1 || sp[0].InChannels[0] != "channel" || len(sp[0].FromUsers) != 1 || sp[0].FromUsers[0] != "someone" { t.Fatalf("Incorrect output from parse search params: %v", sp[0]) } + + 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]) + } } diff --git a/model/utils.go b/model/utils.go index 70b7e3bbd..719a2ad1b 100644 --- a/model/utils.go +++ b/model/utils.go @@ -298,8 +298,9 @@ func Etag(parts ...interface{}) string { } var validHashtag = regexp.MustCompile(`^(#[A-Za-zäöüÄÖÜß]+[A-Za-z0-9äöüÄÖÜß_\-]*[A-Za-z0-9äöüÄÖÜß])$`) -var puncStart = regexp.MustCompile(`^[.,()&$!\?\[\]{}':;\\]+`) -var puncEnd = regexp.MustCompile(`[.,()&$#!\?\[\]{}';\\]+$`) +var puncStart = regexp.MustCompile(`^[.,()&$!\?\[\]{}':;\\<>\-+=%^*|]+`) +var hashtagStart = regexp.MustCompile(`^#{2,}`) +var puncEnd = regexp.MustCompile(`[.,()&$#!\?\[\]{}':;\\<>\-+=%^*|]+$`) func ParseHashtags(text string) (string, string) { words := strings.Fields(text) @@ -307,8 +308,13 @@ func ParseHashtags(text string) (string, string) { hashtagString := "" plainString := "" for _, word := range words { + // trim off surrounding punctuation word = puncStart.ReplaceAllString(word, "") word = puncEnd.ReplaceAllString(word, "") + + // and remove extra pound #s + word = hashtagStart.ReplaceAllString(word, "#") + if validHashtag.MatchString(word) { hashtagString += " " + word } else { diff --git a/model/utils_test.go b/model/utils_test.go index 24ee4b7a6..b8eabe264 100644 --- a/model/utils_test.go +++ b/model/utils_test.go @@ -83,19 +83,34 @@ func TestEtag(t *testing.T) { } var hashtags map[string]string = map[string]string{ - "#test": "#test", - "test": "", - "#test123": "#test123", - "#123test123": "", - "#test-test": "#test-test", - "#test?": "#test", - "hi #there": "#there", - "#bug #idea": "#bug #idea", - "#bug or #gif!": "#bug #gif", - "#hüllo": "#hüllo", - "#?test": "", - "#-test": "", - "#yo_yo": "#yo_yo", + "#test": "#test", + "test": "", + "#test123": "#test123", + "#123test123": "", + "#test-test": "#test-test", + "#test?": "#test", + "hi #there": "#there", + "#bug #idea": "#bug #idea", + "#bug or #gif!": "#bug #gif", + "#hüllo": "#hüllo", + "#?test": "", + "#-test": "", + "#yo_yo": "#yo_yo", + "(#brakets)": "#brakets", + ")#stekarb(": "#stekarb", + "<#less_than<": "#less_than", + ">#greater_than>": "#greater_than", + "-#minus-": "#minus", + "+#plus+": "#plus", + "=#equals=": "#equals", + "%#pct%": "#pct", + "&#and&": "#and", + "^#hat^": "#hat", + "##brown#": "#brown", + "*#star*": "#star", + "|#pipe|": "#pipe", + ":#colon:": "#colon", + ";#semi;": "#semi", } func TestParseHashtags(t *testing.T) { -- cgit v1.2.3-1-g7c22 From c2bc9454ce5550a180d8ee9fec75db7f3841b1ad Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Tue, 26 Jan 2016 20:32:24 -0500 Subject: PLT-1586 adding attach device id method --- model/client.go | 11 +++++++++++ model/version.go | 2 +- 2 files changed, 12 insertions(+), 1 deletion(-) (limited to 'model') diff --git a/model/client.go b/model/client.go index 8021c7039..d31ac1592 100644 --- a/model/client.go +++ b/model/client.go @@ -775,6 +775,17 @@ func (c *Client) UpdateUserRoles(data map[string]string) (*Result, *AppError) { } } +func (c *Client) AttachDeviceId(deviceId string) (*Result, *AppError) { + data := make(map[string]string) + data["device_id"] = deviceId + if r, err := c.DoApiPost("/users/attach_device", MapToJson(data)); err != nil { + return nil, err + } else { + return &Result{r.Header.Get(HEADER_REQUEST_ID), + r.Header.Get(HEADER_ETAG_SERVER), UserFromJson(r.Body)}, nil + } +} + func (c *Client) UpdateActive(userId string, active bool) (*Result, *AppError) { data := make(map[string]string) data["user_id"] = userId diff --git a/model/version.go b/model/version.go index 88334ceea..f503ddb84 100644 --- a/model/version.go +++ b/model/version.go @@ -28,7 +28,7 @@ var CurrentVersion string = versions[0] var BuildNumber = "_BUILD_NUMBER_" var BuildDate = "_BUILD_DATE_" var BuildHash = "_BUILD_HASH_" -var BuildEnterpriseReady = "_BUILD_ENTERPRISE_READY_" +var BuildEnterpriseReady = "false" func SplitVersion(version string) (int64, int64, int64) { parts := strings.Split(version, ".") -- cgit v1.2.3-1-g7c22 From 0dec26bb9f3e05a84873996c9ecb3bd87b7dc925 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Tue, 26 Jan 2016 21:11:39 -0500 Subject: Fixing version --- model/version.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'model') diff --git a/model/version.go b/model/version.go index f503ddb84..88334ceea 100644 --- a/model/version.go +++ b/model/version.go @@ -28,7 +28,7 @@ var CurrentVersion string = versions[0] var BuildNumber = "_BUILD_NUMBER_" var BuildDate = "_BUILD_DATE_" var BuildHash = "_BUILD_HASH_" -var BuildEnterpriseReady = "false" +var BuildEnterpriseReady = "_BUILD_ENTERPRISE_READY_" func SplitVersion(version string) (int64, int64, int64) { parts := strings.Split(version, ".") -- cgit v1.2.3-1-g7c22 From dc4b71bba2cad5e85e86cc6ecb743bea84f9ccc8 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Wed, 27 Jan 2016 10:56:15 -0500 Subject: PLT-7 Removing AppError ctor --- model/utils.go | 10 ---------- 1 file changed, 10 deletions(-) (limited to 'model') diff --git a/model/utils.go b/model/utils.go index 719a2ad1b..695d4a0cb 100644 --- a/model/utils.go +++ b/model/utils.go @@ -71,16 +71,6 @@ func AppErrorFromJson(data io.Reader) *AppError { } } -func NewAppError(where string, message string, details string) *AppError { - ap := &AppError{} - ap.Message = message - ap.Where = where - ap.DetailedError = details - ap.StatusCode = 500 - ap.IsOAuth = false - return ap -} - func NewLocAppError(where string, id string, params map[string]interface{}, details string) *AppError { ap := &AppError{} ap.Id = id -- cgit v1.2.3-1-g7c22 From c50b8661ec0c1925062d3d5584ed5899c9e7ff44 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Wed, 27 Jan 2016 11:05:46 -0500 Subject: Fixing build --- model/utils_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'model') diff --git a/model/utils_test.go b/model/utils_test.go index b8eabe264..02a08d113 100644 --- a/model/utils_test.go +++ b/model/utils_test.go @@ -27,7 +27,7 @@ func TestRandomString(t *testing.T) { } func TestAppError(t *testing.T) { - err := NewAppError("TestAppError", "message", "") + err := NewLocAppError("TestAppError", "message", nil, "") json := err.ToJson() rerr := AppErrorFromJson(strings.NewReader(json)) if err.Message != rerr.Message { -- cgit v1.2.3-1-g7c22 From 2138b46f6cdab5fca49680c2e1994703ab71b1c3 Mon Sep 17 00:00:00 2001 From: =Corey Hulen Date: Thu, 28 Jan 2016 11:39:48 -0500 Subject: PLT-1765 allowing support of 2 previous versions --- model/version.go | 60 ++++++++++++++++++++++++++++++++++----------------- model/version_test.go | 52 +++++++++++++++++++++++++++++++++++++------- 2 files changed, 84 insertions(+), 28 deletions(-) (limited to 'model') diff --git a/model/version.go b/model/version.go index 88334ceea..69529e7a1 100644 --- a/model/version.go +++ b/model/version.go @@ -4,6 +4,7 @@ package model import ( + "fmt" "strconv" "strings" ) @@ -29,6 +30,22 @@ var BuildNumber = "_BUILD_NUMBER_" var BuildDate = "_BUILD_DATE_" var BuildHash = "_BUILD_HASH_" var BuildEnterpriseReady = "_BUILD_ENTERPRISE_READY_" +var versionsWithoutHotFixes []string + +func init() { + versionsWithoutHotFixes = make([]string, 0, len(versions)) + seen := make(map[string]string) + + for _, version := range versions { + maj, min, _ := SplitVersion(version) + verStr := fmt.Sprintf("%v.%v.0", maj, min) + + if seen[verStr] == "" { + versionsWithoutHotFixes = append(versionsWithoutHotFixes, verStr) + seen[verStr] = verStr + } + } +} func SplitVersion(version string) (int64, int64, int64) { parts := strings.Split(version, ".") @@ -52,25 +69,17 @@ func SplitVersion(version string) (int64, int64, int64) { return major, minor, patch } -func GetPreviousVersion(currentVersion string) (int64, int64) { - currentIndex := -1 - currentMajor, currentMinor, _ := SplitVersion(currentVersion) - - for index, version := range versions { - major, minor, _ := SplitVersion(version) - - if currentMajor == major && currentMinor == minor { - currentIndex = index - } +func GetPreviousVersion(version string) string { + verMajor, verMinor, _ := SplitVersion(version) + verStr := fmt.Sprintf("%v.%v.0", verMajor, verMinor) - if currentIndex >= 0 { - if currentMajor != major || currentMinor != minor { - return major, minor - } + for index, v := range versionsWithoutHotFixes { + if v == verStr && len(versionsWithoutHotFixes) > index+1 { + return versionsWithoutHotFixes[index+1] } } - return 0, 0 + return "" } func IsOfficalBuild() bool { @@ -88,13 +97,24 @@ func IsCurrentVersion(versionToCheck string) bool { } } -func IsPreviousVersion(versionToCheck string) bool { +func IsPreviousVersionsSupported(versionToCheck string) bool { toCheckMajor, toCheckMinor, _ := SplitVersion(versionToCheck) - prevMajor, prevMinor := GetPreviousVersion(CurrentVersion) + versionToCheckStr := fmt.Sprintf("%v.%v.0", toCheckMajor, toCheckMinor) - if toCheckMajor == prevMajor && toCheckMinor == prevMinor { + // Current Supported + if versionsWithoutHotFixes[0] == versionToCheckStr { + return true + } + + // Current - 1 Supported + if versionsWithoutHotFixes[1] == versionToCheckStr { return true - } else { - return false } + + // Current - 2 Supported + if versionsWithoutHotFixes[2] == versionToCheckStr { + return true + } + + return false } diff --git a/model/version_test.go b/model/version_test.go index 33e8dc93e..d73273ce5 100644 --- a/model/version_test.go +++ b/model/version_test.go @@ -36,20 +36,28 @@ func TestSplitVersion(t *testing.T) { } func TestGetPreviousVersion(t *testing.T) { - if major, minor := GetPreviousVersion("1.0.0"); major != 0 || minor != 7 { - t.Fatal(major, minor) + if GetPreviousVersion("1.3.0") != "1.2.0" { + t.Fatal() + } + + if GetPreviousVersion("1.2.1") != "1.1.0" { + t.Fatal() + } + + if GetPreviousVersion("1.1.0") != "1.0.0" { + t.Fatal() } - if major, minor := GetPreviousVersion("0.7.0"); major != 0 || minor != 6 { - t.Fatal(major, minor) + if GetPreviousVersion("1.0.0") != "0.7.0" { + t.Fatal() } - if major, minor := GetPreviousVersion("0.7.1"); major != 0 || minor != 6 { - t.Fatal(major, minor) + if GetPreviousVersion("0.7.1") != "0.6.0" { + t.Fatal() } - if major, minor := GetPreviousVersion("0.7111.1"); major != 0 || minor != 0 { - t.Fatal(major, minor) + if GetPreviousVersion("0.5.0") != "" { + t.Fatal() } } @@ -72,3 +80,31 @@ func TestIsCurrentVersion(t *testing.T) { t.Fatal() } } + +func TestIsPreviousVersionsSupported(t *testing.T) { + + // 1.4.0 CURRENT RELEASED VERSION + if !IsPreviousVersionsSupported(versions[0]) { + t.Fatal() + } + + // 1.3.0 + if !IsPreviousVersionsSupported(versions[1]) { + t.Fatal() + } + + // 1.2.1 + if !IsPreviousVersionsSupported(versions[2]) { + t.Fatal() + } + + // 1.2.0 + if !IsPreviousVersionsSupported(versions[3]) { + t.Fatal() + } + + // 1.1.0 NOT SUPPORTED + if IsPreviousVersionsSupported(versions[4]) { + t.Fatal() + } +} -- cgit v1.2.3-1-g7c22