Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ private static boolean scanLinkDestinationWithBalancedParens(Scanner scanner) {
char c = scanner.peek();
switch (c) {
case ' ':
return !empty;
return !empty && parens == 0;
case '\\':
scanner.next();
if (isEscapable(scanner.peek())) {
Expand All @@ -149,14 +149,14 @@ private static boolean scanLinkDestinationWithBalancedParens(Scanner scanner) {
default:
// or control character
if (Character.isISOControl(c)) {
return !empty;
return !empty && parens == 0;
}
scanner.next();
break;
}
empty = false;
}
return true;
return parens == 0;
}

private static boolean isEscapable(char c) {
Expand Down
10 changes: 10 additions & 0 deletions commonmark/src/test/java/org/commonmark/test/SpecialInputTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,16 @@ public void linkLabelWithBracket() {
""");
}

@Test
public void linkReferenceDefinitionWithUnbalancedParens() {
// Parentheses in a link destination must be balanced, otherwise it's not a definition
assertRendering("[foo]: (", "<p>[foo]: (</p>\n");
assertRendering("[foo]: (\nbar", "<p>[foo]: (\nbar</p>\n");
assertRendering("[foo]: a(b\n\n[foo]", "<p>[foo]: a(b</p>\n<p>[foo]</p>\n");
assertRendering(
"[foo]: a(b) \"t\"\n\n[foo]", "<p><a href=\"a(b)\" title=\"t\">foo</a></p>\n");
}

@Test
public void linkLabelLength() {
String label1 = "a".repeat(999);
Expand Down