diff --git a/pkgs/markdown/CHANGELOG.md b/pkgs/markdown/CHANGELOG.md index b67e9751a2..60a2508877 100644 --- a/pkgs/markdown/CHANGELOG.md +++ b/pkgs/markdown/CHANGELOG.md @@ -3,6 +3,7 @@ * Update the README link to the markdown playground (https://dart-lang.github.io/tools). * Update `package:web` API references in the example. +* Fix performance and correctness of HTML comment parser. * Require Dart `^3.4.0`. ## 7.3.0 diff --git a/pkgs/markdown/lib/src/inline_syntaxes/inline_html_syntax.dart b/pkgs/markdown/lib/src/inline_syntaxes/inline_html_syntax.dart index 3a7ce77ddb..6243b01f8c 100644 --- a/pkgs/markdown/lib/src/inline_syntaxes/inline_html_syntax.dart +++ b/pkgs/markdown/lib/src/inline_syntaxes/inline_html_syntax.dart @@ -2,6 +2,9 @@ // for details. All rights reserved. Use of this source code is governed by a // BSD-style license that can be found in the LICENSE file. +// These are RegExps, always use raw strings. +// ignore_for_file: unnecessary_raw_strings + import '../../markdown.dart'; import '../charcode.dart'; import '../patterns.dart'; @@ -22,23 +25,23 @@ class InlineHtmlSyntax extends TextSyntax { // HTML comment, see // https://spec.commonmark.org/0.30/#html-comment. - '' + r'` is needed. + // The number of lines increase time exponentially. + // The length of lines affect the base of the exponentiation. + // Locally, three "Lorem-ipsum" lines ran in ~6 seconds, two in < 200 ms. + // Adding a fourth line should ensure it cannot possibly finish in ten + // seconds if the bug isn't fixed. + const input = ''' +a +'''; + + final time = Stopwatch()..start(); + final html = markdownToHtml(input); // Should not hang. + expect(html, isNotNull); // To use the output. + final elapsed = time.elapsedMilliseconds; + expect(elapsed, lessThan(10000)); + }); + + test('HTML comment with lt/gt', () { + // Incorrect parsing found as part of fixing #2119. + // Now matches `` where text + // does not start with `>` or `->`, does not end with `-`, + // and does not contain `--`. + const input = 'a '; + final html = markdownToHtml(input); + expect(html, '

$input

\n'); + }); +}