Skip to content
This repository was archived by the owner on Feb 24, 2025. It is now read-only.
Merged
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
## 7.2.4

* Fix several `RangeError` hazards in links (#623).

## 7.2.3

* Fix an issue with checkbox list items separated with blank lines (#602).
Expand Down
6 changes: 6 additions & 0 deletions lib/src/inline_syntaxes/link_syntax.dart
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ class LinkSyntax extends DelimiterSyntax {
final char = parser.charAt(parser.pos);
if (char == $backslash) {
parser.advanceBy(1);
if (parser.isDone) return null;
final next = parser.charAt(parser.pos);
if (next != $backslash && next != $rbracket) {
buffer.writeCharCode(char);
Expand Down Expand Up @@ -273,12 +274,14 @@ class LinkSyntax extends DelimiterSyntax {
/// Returns the link if it was successfully created, `null` otherwise.
InlineLink? _parseInlineBracketedLink(InlineParser parser) {
parser.advanceBy(1);
if (parser.isDone) return null;

final buffer = StringBuffer();
while (true) {
final char = parser.charAt(parser.pos);
if (char == $backslash) {
parser.advanceBy(1);
if (parser.isDone) return null;
final next = parser.charAt(parser.pos);
// TODO: Follow the backslash spec better here.
// https://spec.commonmark.org/0.30/#backslash-escapes
Expand All @@ -302,6 +305,7 @@ class LinkSyntax extends DelimiterSyntax {
final destination = buffer.toString();

parser.advanceBy(1);
if (parser.isDone) return null;
final char = parser.charAt(parser.pos);
if (char == $space || char == $lf || char == $cr || char == $ff) {
final title = _parseTitle(parser);
Expand Down Expand Up @@ -433,13 +437,15 @@ class LinkSyntax extends DelimiterSyntax {

final closeDelimiter = delimiter == $lparen ? $rparen : delimiter;
parser.advanceBy(1);
if (parser.isDone) return null;

// Now we look for an un-escaped closing delimiter.
final buffer = StringBuffer();
while (true) {
final char = parser.charAt(parser.pos);
if (char == $backslash) {
parser.advanceBy(1);
if (parser.isDone) return null;
final next = parser.charAt(parser.pos);
if (next != $backslash && next != closeDelimiter) {
buffer.writeCharCode(char);
Expand Down
2 changes: 1 addition & 1 deletion lib/src/version.dart

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion pubspec.yaml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
name: markdown
version: 7.2.3
version: 7.2.4
description: >-
A portable Markdown library written in Dart that can parse Markdown into HTML.
repository: https://github.com/dart-lang/markdown
Expand Down
36 changes: 36 additions & 0 deletions test/markdown_test.dart
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,42 @@ void main() async {
5 Ethernet ([Music](
''', '''
<p>5 Ethernet ([Music](</p>
''');

validateCore('Incorrect Links - Issue #623 - 1 - Bracketed link 1', '''
[](<
''', '''
<p>[](&lt;</p>
''');

validateCore('Incorrect Links - Issue #623 - 2 - Bracketed link 2', '''
[](<>
''', '''
<p>[](&lt;&gt;</p>
''');

validateCore('Incorrect Links - Issue #623 - 3 - Bracketed link 3', r'''
[](<\
''', r'''
<p>[](&lt;\</p>
''');

validateCore('Incorrect Links - Issue #623 - 4 - Link title 1', '''
[](www.example.com "
''', '''
<p>[](www.example.com &quot;</p>
''');

validateCore('Incorrect Links - Issue #623 - 5 - Link title 2', r'''
[](www.example.com "\
''', r'''
<p>[](www.example.com &quot;\</p>
''');

validateCore('Incorrect Links - Issue #623 - 6 - Reference link label', r'''
[][\
''', r'''
<p>[][\</p>
''');

validateCore('Escaping code block language', '''
Expand Down