Browse Source

Fix crash in linkify inline rule on malformed input

pull/964/head
Alex Kocharin 8 months ago
parent
commit
80a3adc094
  1. 7
      CHANGELOG.md
  2. 4
      lib/rules_inline/linkify.js
  3. 7
      test/fixtures/markdown-it/linkify.txt

7
CHANGELOG.md

@ -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
@ -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

4
lib/rules_inline/linkify.js

@ -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(/\*+$/, '');

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

@ -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>
.

Loading…
Cancel
Save