summaryrefslogtreecommitdiffstats
path: root/app/slackimport.go
diff options
context:
space:
mode:
authorGeorge Goldberg <george@gberg.me>2017-07-19 21:57:28 +0100
committerChristopher Speller <crspeller@gmail.com>2017-07-19 13:57:28 -0700
commit5f8a93fca66215d5c6a16297cfb649ce15526044 (patch)
tree5074ce219b7997101a24086ee3bf255e22fd1b9c /app/slackimport.go
parentecb82dbd1286f0cc722c082eada862b35fe92105 (diff)
downloadchat-5f8a93fca66215d5c6a16297cfb649ce15526044.tar.gz
chat-5f8a93fca66215d5c6a16297cfb649ce15526044.tar.bz2
chat-5f8a93fca66215d5c6a16297cfb649ce15526044.zip
PLT-6971: Fix Slack Import of non-ascii channel names. (#6969)
Diffstat (limited to 'app/slackimport.go')
-rw-r--r--app/slackimport.go12
1 files changed, 9 insertions, 3 deletions
diff --git a/app/slackimport.go b/app/slackimport.go
index 71f16c874..4470b8323 100644
--- a/app/slackimport.go
+++ b/app/slackimport.go
@@ -53,6 +53,8 @@ type SlackPost struct {
Attachments []*model.SlackAttachment `json:"attachments"`
}
+var isValidChannelNameCharacters = regexp.MustCompile(`^[a-zA-Z0-9\-_]+$`).MatchString
+
type SlackComment struct {
User string `json:"user"`
Comment string `json:"comment"`
@@ -77,13 +79,17 @@ func SlackConvertTimeStamp(ts string) int64 {
return timeStamp * 1000 // Convert to milliseconds
}
-func SlackConvertChannelName(channelName string) string {
+func SlackConvertChannelName(channelName string, channelId string) string {
newName := strings.Trim(channelName, "_-")
if len(newName) == 1 {
return "slack-channel-" + newName
}
- return newName
+ if isValidChannelNameCharacters(newName) {
+ return newName
+ } else {
+ return strings.ToLower(channelId)
+ }
}
func SlackParseChannels(data io.Reader) ([]SlackChannel, error) {
@@ -466,7 +472,7 @@ func SlackAddChannels(teamId string, slackchannels []SlackChannel, posts map[str
TeamId: teamId,
Type: model.CHANNEL_OPEN,
DisplayName: sChannel.Name,
- Name: SlackConvertChannelName(sChannel.Name),
+ Name: SlackConvertChannelName(sChannel.Name, sChannel.Id),
Purpose: sChannel.Purpose["value"],
Header: sChannel.Topic["value"],
}