Browse Source

Fix quadratic compexity on backticks

close https://github.com/markdown-it/markdown-it/issues/736
pull/745/head
Alex Kocharin 4 years ago
parent
commit
8cd6fc34c4
  1. 2
      CHANGELOG.md
  2. 8
      lib/rules_inline/backticks.js
  3. 4
      test/pathological.js

2
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.

8
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;

4
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));
});
});
});

Loading…
Cancel
Save