From 8cd6fc34c4110955b408d21d9898f6fbcdd567fa Mon Sep 17 00:00:00 2001 From: Alex Kocharin Date: Wed, 25 Nov 2020 16:23:03 +0300 Subject: [PATCH] Fix quadratic compexity on backticks close https://github.com/markdown-it/markdown-it/issues/736 --- CHANGELOG.md | 2 +- lib/rules_inline/backticks.js | 8 +++----- test/pathological.js | 4 ++++ 3 files changed, 8 insertions(+), 6 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 45e4e5c03..40200b257 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -12,7 +12,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - `[](url (xxx())` is no longer a valid link. - `[](url\ xxx)` is no longer a valid link. - Fix performance issues when parsing links, #732, #734. -- Fix performance issues when parsing backticks, #733. +- Fix performance issues when parsing backticks, #733, #736. - Fix performance issues when parsing emphases, #735. diff --git a/lib/rules_inline/backticks.js b/lib/rules_inline/backticks.js index f7c3d1d0a..b9c9ddb7b 100644 --- a/lib/rules_inline/backticks.js +++ b/lib/rules_inline/backticks.js @@ -52,13 +52,11 @@ module.exports = function backtick(state, silent) { // Some different length found, put it in cache as upper limit of where closer can be found state.backticks[closerLength] = matchStart; - - // Scanned through the end, didn't find anything - if (matchEnd >= max) { - state.backticksScanned = true; - } } + // Scanned through the end, didn't find anything + state.backticksScanned = true; + if (!silent) state.pending += marker; state.pos += openerLength; return true; diff --git a/test/pathological.js b/test/pathological.js index a905dc551..fbbffddd7 100644 --- a/test/pathological.js +++ b/test/pathological.js @@ -122,5 +122,9 @@ describe('Pathological sequences speed', () => { it('emphasis **_* pattern', async () => { await test_pattern('**_* '.repeat(50000)); }); + + it('backtick ``\\``\\`` pattern', async () => { + await test_pattern('``\\'.repeat(50000)); + }); }); });