Skip to content

Commit 9b4f670

Browse files
committed
don't allow | as part of a URL
This was an unintended bug added ages ago. In c64477d, we modified midChar to add \p{Po} to the character set. Unfortunately, we added |, essentially ending up with [somechars|\p{Po}]. In other words, | was now part of the set, while we only meant it as a regex "or" operator. Fix this, and add a test. Fixes #26.
1 parent 9058190 commit 9b4f670

File tree

2 files changed

+3
-2
lines changed

2 files changed

+3
-2
lines changed

xurls.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ const (
2121
otherSymb = `\p{So}`
2222
endChar = iriChar + `/\-+_&~*%=#` + currency + otherSymb
2323
otherPunc = `\p{Po}`
24-
midChar = endChar + `|` + otherPunc
24+
midChar = endChar + otherPunc
2525
wellParen = `\([` + midChar + `]*(\([` + midChar + `]*\)[` + midChar + `]*)*\)`
2626
wellBrack = `\[[` + midChar + `]*(\[[` + midChar + `]*\][` + midChar + `]*)*\]`
2727
wellBrace = `\{[` + midChar + `]*(\{[` + midChar + `]*\}[` + midChar + `]*)*\}`

xurls_test.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ var constantTestCases = []testCase{
104104
{`'http://foo.com/bar'`, `http://foo.com/bar`},
105105
{`'http://foo.com/bar'more`, `http://foo.com/bar'more`},
106106
{`"http://foo.com/bar"`, `http://foo.com/bar`},
107-
{`http://a.b/a0/-+_&~*%=#@.,:;'?!|[]()a`, true},
107+
{`http://a.b/a0/-+_&~*%=#@.,:;'?![]()a`, true},
108108
{`http://a.b/a0/$€¥`, true},
109109
{`http://✪foo.bar/pa✪th©more`, true},
110110
{`http://foo.bar/path/`, true},
@@ -126,6 +126,7 @@ var constantTestCases = []testCase{
126126
{`http://foo.bar/path!`, `http://foo.bar/path`},
127127
{`http://foo.bar/path@`, `http://foo.bar/path`},
128128
{`http://foo.bar/path|`, `http://foo.bar/path`},
129+
{`http://foo.bar/path|more`, `http://foo.bar/path`},
129130
{`http://foo.bar/path<`, `http://foo.bar/path`},
130131
{`http://foo.bar/path<more`, `http://foo.bar/path`},
131132
{`http://foo.com/path_(more)`, true},

0 commit comments

Comments
 (0)