Browse Source

Fix crash when processing strikethrough

close https://github.com/markdown-it/markdown-it/issues/742
pull/745/head
Alex Kocharin 4 years ago
parent
commit
c9dd942246
  1. 5
      CHANGELOG.md
  2. 4
      lib/rules_inline/balance_pairs.js
  3. 2
      lib/rules_inline/strikethrough.js
  4. 7
      test/fixtures/markdown-it/strikethrough.txt

5
CHANGELOG.md

@ -6,6 +6,11 @@ The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
## [12.0.4] - WIP
### Fixed
- Fix crash introduced in `12.0.3` when processing strikethrough (`~~`) and similar plugins, #742.
## [12.0.3] - 2020-12-07
### Fixed
- `[](<foo<bar>)` is no longer a valid link.

4
lib/rules_inline/balance_pairs.js

@ -29,6 +29,10 @@ function processDelimiters(state, delimiters) {
minOpenerIdx = openersBottom[closer.marker][closer.length % 3];
openerIdx = closerIdx - closer.jump - 1;
// avoid crash if `closer.jump` is pointing outside of the array, see #742
if (openerIdx < -1) openerIdx = -1;
newMinOpenerIdx = openerIdx;
for (; openerIdx > minOpenerIdx; openerIdx -= opener.jump + 1) {

2
lib/rules_inline/strikethrough.js

@ -33,7 +33,7 @@ module.exports.tokenize = function strikethrough(state, silent) {
state.delimiters.push({
marker: marker,
length: 0, // disable "rule of 3" length checks meant for emphasis
jump: i,
jump: i / 2, // for `~~` 1 marker = 2 characters
token: state.tokens.length - 1,
end: -1,
open: scanned.can_open,

7
test/fixtures/markdown-it/strikethrough.txt

@ -127,3 +127,10 @@ Coverage: single tilde
.
<p>~a~</p>
.
Regression test for #742:
.
-~~~~;~~~~~~
.
<p>-<s><s>;</s></s>~~</p>
.

Loading…
Cancel
Save