diff --git a/xurls.go b/xurls.go index 8ecd863..e29a194 100644 --- a/xurls.go +++ b/xurls.go @@ -76,7 +76,7 @@ func relaxedExp() string { knownTLDs := anyOf(append(TLDs, PseudoTLDs...)...) site := domain + `(?i)(` + punycode + `|` + knownTLDs + `)(?-i)` hostName := `(` + site + `|` + ipAddr + `)` - webURL := hostName + port + `(/|/` + pathCont + `?|\b|$)` + webURL := hostName + port + `(/|/` + pathCont + `?|\b|(?m)$)` return strictExp() + `|` + webURL } diff --git a/xurls_test.go b/xurls_test.go index 4b359f0..a99003b 100644 --- a/xurls_test.go +++ b/xurls_test.go @@ -29,10 +29,13 @@ func wantStr(in string, want interface{}) string { func doTest(t *testing.T, name string, re *regexp.Regexp, cases []testCase) { for i, c := range cases { t.Run(fmt.Sprintf("%s/%03d", name, i), func(t *testing.T) { - got := re.FindString(c.in) want := wantStr(c.in, c.want) - if got != want { - t.Errorf(`%s.FindString("%s") got "%s", want "%s"`, name, c.in, got, want) + for _, surround := range []string{"", "\n"} { + in := surround + c.in + surround + got := re.FindString(in) + if got != want { + t.Errorf(`FindString(%q) got %q, want %q`, in, got, want) + } } }) }