Skip to content

Commit

Permalink
use (?m) when looking for an end-of-line
Browse files Browse the repository at this point in the history
Without it, it only matches the end of the entire input.

Fixes #28, again.
  • Loading branch information
mvdan committed Jul 27, 2019
1 parent 9b4f670 commit 633779b
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 4 deletions.
2 changes: 1 addition & 1 deletion xurls.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
}

Expand Down
9 changes: 6 additions & 3 deletions xurls_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
})
}
Expand Down

0 comments on commit 633779b

Please sign in to comment.