Skip to content

Commit 51a53ab

Browse files
committed
Stop URLs on ` (grave accent, backtick) as well
It's not a valid URI character according to RFC 3986 and the URL Standard lists them as part of the percent-encoded set, same as space, ", < and >.
1 parent bad17c6 commit 51a53ab

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/main/java/org/nibor/autolink/internal/Scanners.java

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,10 +61,13 @@ public static int findUrlEnd(CharSequence input, int beginIndex) {
6161
case '\u001D':
6262
case '\u001E':
6363
case '\u001F':
64+
// These are part of "fragment percent-encode set" which means they need to be
65+
// percent-encoded in an URL: https://url.spec.whatwg.org/#fragment-percent-encode-set
6466
case ' ':
6567
case '\"':
6668
case '<':
6769
case '>':
70+
case '`':
6871
case '\u007F':
6972
case '\u0080':
7073
case '\u0081':
@@ -100,7 +103,7 @@ public static int findUrlEnd(CharSequence input, int beginIndex) {
100103
case '\u009F':
101104
// The above can never be part of an URL, so stop now. See RFC 3986 and RFC 3987.
102105
// Some characters are not in the above list, even they are not in "unreserved" or "reserved":
103-
// '\\', '^', '`', '{', '|', '}'
106+
// '\\', '^', '{', '|', '}'
104107
// The reason for this is that other link detectors also allow them. Also see below, we require
105108
// the braces to be balanced.
106109
case '\u00A0': // no-break space

src/test/java/org/nibor/autolink/AutolinkUrlTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -153,6 +153,9 @@ public void quotes() {
153153
// " not allowed in URLs
154154
assertLinked("http://example.org/\"a", "|http://example.org/|\"a");
155155
assertLinked("http://example.org/\"a\"", "|http://example.org/|\"a\"");
156+
// ` not allowed in URLs
157+
assertLinked("http://example.org/`a", "|http://example.org/|`a");
158+
assertLinked("http://example.org/`a`", "|http://example.org/|`a`");
156159
}
157160

158161
@Test

0 commit comments

Comments
 (0)