Skip to content

Commit 633779b

Browse files
committed
use (?m) when looking for an end-of-line
Without it, it only matches the end of the entire input. Fixes #28, again.
1 parent 9b4f670 commit 633779b

File tree

2 files changed

+7
-4
lines changed

2 files changed

+7
-4
lines changed

xurls.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func relaxedExp() string {
7676
knownTLDs := anyOf(append(TLDs, PseudoTLDs...)...)
7777
site := domain + `(?i)(` + punycode + `|` + knownTLDs + `)(?-i)`
7878
hostName := `(` + site + `|` + ipAddr + `)`
79-
webURL := hostName + port + `(/|/` + pathCont + `?|\b|$)`
79+
webURL := hostName + port + `(/|/` + pathCont + `?|\b|(?m)$)`
8080
return strictExp() + `|` + webURL
8181
}
8282

xurls_test.go

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,13 @@ func wantStr(in string, want interface{}) string {
2929
func doTest(t *testing.T, name string, re *regexp.Regexp, cases []testCase) {
3030
for i, c := range cases {
3131
t.Run(fmt.Sprintf("%s/%03d", name, i), func(t *testing.T) {
32-
got := re.FindString(c.in)
3332
want := wantStr(c.in, c.want)
34-
if got != want {
35-
t.Errorf(`%s.FindString("%s") got "%s", want "%s"`, name, c.in, got, want)
33+
for _, surround := range []string{"", "\n"} {
34+
in := surround + c.in + surround
35+
got := re.FindString(in)
36+
if got != want {
37+
t.Errorf(`FindString(%q) got %q, want %q`, in, got, want)
38+
}
3639
}
3740
})
3841
}

0 commit comments

Comments
 (0)