Skip to content

Commit 0c1c09d

Browse files
authored
* Fixes dart-lang/markdown#230: links with unbalanced parentheses * Fixes dart-lang/markdown#233: exception on invalid link * fix formatting
1 parent 473aeb1 commit 0c1c09d

File tree

3 files changed

+15
-3
lines changed

3 files changed

+15
-3
lines changed

pkgs/markdown/lib/src/inline_parser.dart

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -895,7 +895,8 @@ class LinkSyntax extends TagSyntax {
895895
case $ff:
896896
var destination = buffer.toString();
897897
var title = _parseTitle(parser);
898-
if (title == null && parser.charAt(parser.pos) != $rparen) {
898+
if (title == null &&
899+
(parser.isDone || parser.charAt(parser.pos) != $rparen)) {
899900
// This looked like an inline link, until we found this $space
900901
// followed by mystery characters; no longer a link.
901902
return null;
@@ -933,7 +934,7 @@ class LinkSyntax extends TagSyntax {
933934

934935
// Walk the parser forward through any whitespace.
935936
void _moveThroughWhitespace(InlineParser parser) {
936-
while (true) {
937+
while (!parser.isDone) {
937938
var char = parser.charAt(parser.pos);
938939
if (char != $space &&
939940
char != $tab &&
@@ -944,7 +945,6 @@ class LinkSyntax extends TagSyntax {
944945
return;
945946
}
946947
parser.advanceBy(1);
947-
if (parser.isDone) return;
948948
}
949949
}
950950

pkgs/markdown/test/markdown_test.dart

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,14 @@ void main() {
2323
testFile('extensions/emojis.unit', inlineSyntaxes: [EmojiSyntax()]);
2424
testFile('extensions/inline_html.unit', inlineSyntaxes: [InlineHtmlSyntax()]);
2525

26+
group('Corner cases', () {
27+
validateCore('Incorrect Links', '''
28+
5 Ethernet ([Music](
29+
''', '''
30+
<p>5 Ethernet ([Music](</p>
31+
''');
32+
});
33+
2634
group('Resolver', () {
2735
Node nyanResolver(String text, [_]) =>
2836
text.isEmpty ? null : Text('~=[,,_${text}_,,]:3');

pkgs/markdown/test/original/inline_links.unit

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -76,3 +76,7 @@ links [are *awesome*]
7676
<a href="(yes-a-link)">a</a>
7777
[a](\(not-a-link))
7878
<a href="(yes-a-link))">a</a></p>
79+
>>> links with unbalanced parentheses
80+
[foo](link(1.png) (what?)
81+
<<<
82+
<p>[foo](link(1.png) (what?)</p>

0 commit comments

Comments
 (0)