Skip to content

Commit

Permalink
Merge pull request #103 from rusq/wksp-name
Browse files Browse the repository at this point in the history
Fix URL parsing regexp to allow for spaces
  • Loading branch information
rusq authored Aug 4, 2022
2 parents 9509081 + 0cb46fc commit dbc992f
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
2 changes: 1 addition & 1 deletion internal/structures/url_parse.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ func ParseURL(slackURL string) (*SlackLink, error) {
}

// Sample: https://ora600.slack.com/archives/CHM82GF99/p1577694990000400
var slackURLRe = regexp.MustCompile(`^https:\/\/[\w]+\.slack\.com\/archives\/[A-Z]{1}[A-Z0-9]+(\/p(\d+))?$`)
var slackURLRe = regexp.MustCompile(`^https:\/\/[a-zA-Z0-9]{1}[-\w]+\.slack\.com\/archives\/[A-Z]{1}[A-Z0-9]+(\/p(\d+))?$`)

// IsValidSlackURL returns true if the value looks like valid Slack URL, false
// if not.
Expand Down
13 changes: 10 additions & 3 deletions internal/structures/url_parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,10 @@ import (
)

const (
sampleChannelURL = "https://ora600.slack.com/archives/CHM82GF99"
sampleThreadURL = "https://ora600.slack.com/archives/CHM82GF99/p1577694990000400"
sampleDMURL = "https://ora600.slack.com/archives/DL98HT3QA"
sampleChannelURL = "https://ora600.slack.com/archives/CHM82GF99"
sampleThreadURL = "https://ora600.slack.com/archives/CHM82GF99/p1577694990000400"
sampleThreadWDashURL = "https://ora-600.slack.com/archives/CHM82GF99/p1577694990000400"
sampleDMURL = "https://ora600.slack.com/archives/DL98HT3QA"

sampleChannelID = "CHM82GF99"
sampleThreadTS = "p1577694990000400"
Expand Down Expand Up @@ -36,6 +37,12 @@ func TestParseURL(t *testing.T) {
want: &SlackLink{Channel: "CHM82GF99", ThreadTS: "1577694990.000400"},
wantErr: false,
},
{
name: "thread",
args: args{sampleThreadWDashURL},
want: &SlackLink{Channel: "CHM82GF99", ThreadTS: "1577694990.000400"},
wantErr: false,
},
{
name: "thread with extra data in the URL",
args: args{sampleThreadURL + "/xxxx"},
Expand Down

0 comments on commit dbc992f

Please sign in to comment.