Fix infinite loop when using carriage returns

Closes wooorm/remark#195.
This commit is contained in:
Titus Wormer 2016-07-06 20:17:58 +02:00
parent 622540e6fc
commit 7e926561ec
3 changed files with 21 additions and 1 deletions

View File

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

@ -0,0 +1,6 @@
---
title: "Example # "
---
# Establishing an example #
Description.

View File

@ -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'
]);
});
});
/*