|
| 1 | +// Copyright (c) 2025, the Dart project authors. Please see the AUTHORS file |
| 2 | +// for details. All rights reserved. Use of this source code is governed by a |
| 3 | +// BSD-style license that can be found in the LICENSE file. |
| 4 | + |
| 5 | +import 'package:markdown/markdown.dart'; |
| 6 | +import 'package:test/test.dart'; |
| 7 | + |
| 8 | +void main() { |
| 9 | + test('HTML comment with dashes #2119', () { |
| 10 | + // See https://dartbug.com/tools/2119. |
| 11 | + // For this issue, the leading letter was needed, |
| 12 | + // an HTML comment starting a line is handled by a different path. |
| 13 | + // The empty line before the `-->` is needed. |
| 14 | + // The number of lines increase time exponentially. |
| 15 | + // The length of lines affect the base of the exponentiation. |
| 16 | + // Locally, three "Lorem-ipsum" lines ran in ~6 seconds, two in < 200 ms. |
| 17 | + // Adding a fourth line should ensure it cannot possibly finish in ten |
| 18 | + // seconds if the bug isn't fixed. |
| 19 | + const input = ''' |
| 20 | +a <!-- |
| 21 | + - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod |
| 22 | + tempor incididunt ut labore et dolore magna aliqua. |
| 23 | + Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi |
| 24 | + ut aliquip ex ea commodo consequat. |
| 25 | + - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod |
| 26 | + tempor incididunt ut labore et dolore magna aliqua. |
| 27 | + Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi |
| 28 | + ut aliquip ex ea commodo consequat. |
| 29 | + - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod |
| 30 | + tempor incididunt ut labore et dolore magna aliqua. |
| 31 | + Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi |
| 32 | + ut aliquip ex ea commodo consequat. |
| 33 | + - Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod |
| 34 | + tempor incididunt ut labore et dolore magna aliqua. |
| 35 | + Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi |
| 36 | + ut aliquip ex ea commodo consequat. |
| 37 | +--> |
| 38 | +'''; |
| 39 | + |
| 40 | + final time = Stopwatch()..start(); |
| 41 | + final html = markdownToHtml(input); // Should not hang. |
| 42 | + expect(html, isNotNull); // To use the output. |
| 43 | + final elapsed = time.elapsedMilliseconds; |
| 44 | + expect(elapsed, lessThan(10000)); |
| 45 | + }); |
| 46 | + |
| 47 | + test('HTML comment with lt/gt', () { |
| 48 | + // Incorrect parsing found as part of fixing #2119. |
| 49 | + // Now matches `<!--$text-->` where text |
| 50 | + // does not start with `>` or `->`, does not end with `-`, |
| 51 | + // and does not contain `--`. |
| 52 | + const input = 'a <!--<->>-<!-->'; |
| 53 | + final html = markdownToHtml(input); |
| 54 | + expect(html, '<p>$input</p>\n'); |
| 55 | + }); |
| 56 | +} |
0 commit comments