Skip to content

Commit

Permalink
Fix crash when processing strikethrough
Browse files Browse the repository at this point in the history
close #742
  • Loading branch information
rlidwka committed Dec 14, 2020
1 parent ef59691 commit c9dd942
Show file tree
Hide file tree
Showing 4 changed files with 18 additions and 2 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Expand Up @@ -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.
Expand Down
4 changes: 4 additions & 0 deletions lib/rules_inline/balance_pairs.js
Expand Up @@ -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) {
Expand Down
4 changes: 2 additions & 2 deletions lib/rules_inline/strikethrough.js
Expand Up @@ -32,8 +32,8 @@ 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,
length: 0, // disable "rule of 3" length checks meant for emphasis
jump: i / 2, // for `~~` 1 marker = 2 characters
token: state.tokens.length - 1,
end: -1,
open: scanned.can_open,
Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/markdown-it/strikethrough.txt
Expand Up @@ -127,3 +127,10 @@ Coverage: single tilde
.
<p>~a~</p>
.

Regression test for #742:
.
-~~~~;~~~~~~
.
<p>-<s><s>;</s></s>~~</p>
.

0 comments on commit c9dd942

Please sign in to comment.