Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix URL parsing regexp to allow for spaces #103

Merged
merged 1 commit into from
Aug 4, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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