mirror of
https://github.com/remarkjs/remark-lint.git
synced 2024-09-11 19:57:15 +03:00
Fix infinite loop when using carriage returns
Closes wooorm/remark#195.
This commit is contained in:
parent
622540e6fc
commit
7e926561ec
@ -65,6 +65,7 @@ function noHeadingContentIndent(ast, file, preferred, done) {
|
||||
var diff;
|
||||
var word;
|
||||
var index;
|
||||
var char;
|
||||
|
||||
if (position.generated(node)) {
|
||||
return;
|
||||
@ -73,9 +74,16 @@ function noHeadingContentIndent(ast, file, preferred, done) {
|
||||
if (type === 'atx' || type === 'atx-closed') {
|
||||
initial = start(node);
|
||||
index = initial.offset;
|
||||
char = contents.charAt(index);
|
||||
|
||||
while (contents.charAt(index) !== '#') {
|
||||
while (char && char !== '#') {
|
||||
index++;
|
||||
char = contents.charAt(index);
|
||||
}
|
||||
|
||||
/* CR/LF bug: wooorm/remark#195. */
|
||||
if (!char) {
|
||||
return;
|
||||
}
|
||||
|
||||
index = depth + (index - initial.offset);
|
||||
|
6
test/fixtures/carriage-returns.md
vendored
Normal file
6
test/fixtures/carriage-returns.md
vendored
Normal file
@ -0,0 +1,6 @@
|
||||
---
|
||||
title: "Example #
"
|
||||
---
|
||||
# Establishing an example #
|
||||
|
||||
Description.
|
@ -219,6 +219,12 @@ describe('remark-lint', function () {
|
||||
'maximum-line-length-valid.md:22:40: Line must be at most 20 characters'
|
||||
]);
|
||||
});
|
||||
|
||||
it('should work with carriage returns', function () {
|
||||
dequal(process('carriage-returns.md').map(String), [
|
||||
'carriage-returns.md:5:1-5:28: Missing blank line before block node'
|
||||
]);
|
||||
});
|
||||
});
|
||||
|
||||
/*
|
||||
|
Loading…
Reference in New Issue
Block a user