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. 4
      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.
- `[](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 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. - Fix performance issues when parsing emphases, #735.

4
lib/rules_inline/backticks.js

@ -52,12 +52,10 @@ module.exports = function backtick(state, silent) {
// Some different length found, put it in cache as upper limit of where closer can be found // Some different length found, put it in cache as upper limit of where closer can be found
state.backticks[closerLength] = matchStart; state.backticks[closerLength] = matchStart;
}
// Scanned through the end, didn't find anything // Scanned through the end, didn't find anything
if (matchEnd >= max) {
state.backticksScanned = true; state.backticksScanned = true;
}
}
if (!silent) state.pending += marker; if (!silent) state.pending += marker;
state.pos += openerLength; state.pos += openerLength;

4
test/pathological.js

@ -122,5 +122,9 @@ describe('Pathological sequences speed', () => {
it('emphasis **_* pattern', async () => { it('emphasis **_* pattern', async () => {
await test_pattern('**_* '.repeat(50000)); await test_pattern('**_* '.repeat(50000));
}); });
it('backtick ``\\``\\`` pattern', async () => {
await test_pattern('``\\'.repeat(50000));
});
}); });
}); });

Loading…
Cancel
Save