Skip to content

Commit

Permalink
Fix quadratic compexity on backticks, try #2
Browse files Browse the repository at this point in the history
close #736
  • Loading branch information
rlidwka committed Nov 25, 2020
1 parent 2290e10 commit 2abb93c
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
2 changes: 1 addition & 1 deletion CHANGELOG.md
Expand Up @@ -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.


Expand Down
8 changes: 3 additions & 5 deletions lib/rules_inline/backticks.js
Expand Up @@ -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;
Expand Down
4 changes: 4 additions & 0 deletions test/pathological.js
Expand Up @@ -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));
});
});
});

0 comments on commit 2abb93c

Please sign in to comment.