Skip to content

Commit

Permalink
Fix crash in linkify inline rule on malformed input
Browse files Browse the repository at this point in the history
  • Loading branch information
rlidwka committed Sep 26, 2023
1 parent 49ca65b commit 80a3adc
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 3 deletions.
7 changes: 4 additions & 3 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +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).


## [13.1.0] - WIP
### Changed
## [13.0.2] - WIP
### Fixed
- Throw an error if 3rd party plugin doesn't increment `line` or `pos` counters
(previously, markdown-it would likely go into infinite loop instead), #847.
- Fixed crash/infinite loop caused by linkify inline rule, #957.

## [13.0.1] - 2022-05-03
### Fixed
Expand Down Expand Up @@ -621,7 +622,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
- Renamed presets folder (configs -> presets).


[13.1.0]: https://github.com/markdown-it/markdown-it/compare/13.0.1...13.1.0
[13.0.2]: https://github.com/markdown-it/markdown-it/compare/13.0.1...13.0.2
[13.0.1]: https://github.com/markdown-it/markdown-it/compare/13.0.0...13.0.1
[13.0.0]: https://github.com/markdown-it/markdown-it/compare/12.3.2...13.0.0
[12.3.2]: https://github.com/markdown-it/markdown-it/compare/12.3.1...12.3.2
Expand Down
4 changes: 4 additions & 0 deletions lib/rules_inline/linkify.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,10 @@ module.exports = function linkify(state, silent) {

url = link.url;

// invalid link, but still detected by linkify somehow;
// need to check to prevent infinite loop below
if (url.length <= proto.length) return false;

// disallow '*' at the end of the link (conflicts with emphasis)
url = url.replace(/\*+$/, '');

Expand Down
7 changes: 7 additions & 0 deletions test/fixtures/markdown-it/linkify.txt
Original file line number Diff line number Diff line change
Expand Up @@ -167,3 +167,10 @@ https://www.sell.fi/sites/default/files/elainlaakarilehti/tieteelliset_artikkeli
.
<p><a href="https://www.sell.fi/sites/default/files/elainlaakarilehti/tieteelliset_artikkelit/kahkonen_t._et_al.canine_pancreatitis-_review.pdf">https://www.sell.fi/sites/default/files/elainlaakarilehti/tieteelliset_artikkelit/kahkonen_t._et_al.canine_pancreatitis-_review.pdf</a></p>
.

regression test, invalid link:
.
i.org[x[x][xx: htt://a.b://a
.
<p><a href="http://i.org">i.org</a>[x[x][xx: htt://a.b://a</p>
.

0 comments on commit 80a3adc

Please sign in to comment.