From d87cf256f24be553e74dfae3ff738697487a49ca Mon Sep 17 00:00:00 2001 From: tomyeh Date: Fri, 10 Aug 2018 14:10:50 +0800 Subject: [PATCH 1/3] Fix #230: links with unbalanced parentheses --- lib/src/inline_parser.dart | 2 +- test/original/inline_links.unit | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/lib/src/inline_parser.dart b/lib/src/inline_parser.dart index d7e711d5..6f470c51 100644 --- a/lib/src/inline_parser.dart +++ b/lib/src/inline_parser.dart @@ -895,7 +895,7 @@ class LinkSyntax extends TagSyntax { case $ff: var destination = buffer.toString(); var title = _parseTitle(parser); - if (title == null && parser.charAt(parser.pos) != $rparen) { + if (title == null && (parser.isDone || parser.charAt(parser.pos) != $rparen)) { // This looked like an inline link, until we found this $space // followed by mystery characters; no longer a link. return null; diff --git a/test/original/inline_links.unit b/test/original/inline_links.unit index e62cddd1..74afe5af 100644 --- a/test/original/inline_links.unit +++ b/test/original/inline_links.unit @@ -76,3 +76,7 @@ links [are *awesome*] a [a](\(not-a-link)) a

+>>> links with unbalanced parentheses +[foo](link(1.png) (what?) +<<< +

[foo](link(1.png) (what?)

From b623ceba7998d5ca16b032d6a572b800cc4b7c5f Mon Sep 17 00:00:00 2001 From: tomyeh Date: Mon, 17 Sep 2018 12:13:56 +0800 Subject: [PATCH 2/3] Fix #233: exception on invalid link --- lib/src/inline_parser.dart | 3 +-- test/markdown_test.dart | 11 +++++++++++ 2 files changed, 12 insertions(+), 2 deletions(-) diff --git a/lib/src/inline_parser.dart b/lib/src/inline_parser.dart index 6f470c51..48d9fcc5 100644 --- a/lib/src/inline_parser.dart +++ b/lib/src/inline_parser.dart @@ -933,7 +933,7 @@ class LinkSyntax extends TagSyntax { // Walk the parser forward through any whitespace. void _moveThroughWhitespace(InlineParser parser) { - while (true) { + while (!parser.isDone) { var char = parser.charAt(parser.pos); if (char != $space && char != $tab && @@ -944,7 +944,6 @@ class LinkSyntax extends TagSyntax { return; } parser.advanceBy(1); - if (parser.isDone) return; } } diff --git a/test/markdown_test.dart b/test/markdown_test.dart index 87b50936..b33bf245 100644 --- a/test/markdown_test.dart +++ b/test/markdown_test.dart @@ -23,6 +23,17 @@ void main() { testFile('extensions/emojis.unit', inlineSyntaxes: [EmojiSyntax()]); testFile('extensions/inline_html.unit', inlineSyntaxes: [InlineHtmlSyntax()]); + group('Corner cases', () { + validateCore( + 'Incorrect Links', + ''' +5 Ethernet ([Music]( +''', + ''' +

5 Ethernet ([Music](

+'''); + }); + group('Resolver', () { Node nyanResolver(String text, [_]) => text.isEmpty ? null : Text('~=[,,_${text}_,,]:3'); From df869f4c2df189fd994892a03353d9680db4b6c9 Mon Sep 17 00:00:00 2001 From: Kevin Moore Date: Mon, 25 Mar 2019 14:15:17 -0700 Subject: [PATCH 3/3] fix formatting --- lib/src/inline_parser.dart | 3 ++- test/markdown_test.dart | 9 +++------ 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/lib/src/inline_parser.dart b/lib/src/inline_parser.dart index 48d9fcc5..bf959667 100644 --- a/lib/src/inline_parser.dart +++ b/lib/src/inline_parser.dart @@ -895,7 +895,8 @@ class LinkSyntax extends TagSyntax { case $ff: var destination = buffer.toString(); var title = _parseTitle(parser); - if (title == null && (parser.isDone || parser.charAt(parser.pos) != $rparen)) { + if (title == null && + (parser.isDone || parser.charAt(parser.pos) != $rparen)) { // This looked like an inline link, until we found this $space // followed by mystery characters; no longer a link. return null; diff --git a/test/markdown_test.dart b/test/markdown_test.dart index b33bf245..0c8d598c 100644 --- a/test/markdown_test.dart +++ b/test/markdown_test.dart @@ -24,15 +24,12 @@ void main() { testFile('extensions/inline_html.unit', inlineSyntaxes: [InlineHtmlSyntax()]); group('Corner cases', () { - validateCore( - 'Incorrect Links', - ''' + validateCore('Incorrect Links', ''' 5 Ethernet ([Music]( -''', - ''' +''', '''

5 Ethernet ([Music](

'''); - }); + }); group('Resolver', () { Node nyanResolver(String text, [_]) =>