Skip to content

Commit

Permalink
Fix infinite loop when using carriage returns
Browse files Browse the repository at this point in the history
  • Loading branch information
wooorm committed Jul 6, 2016
1 parent 622540e commit 7e92656
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 1 deletion.
10 changes: 9 additions & 1 deletion lib/rules/no-heading-content-indent.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ function noHeadingContentIndent(ast, file, preferred, done) {
var diff;
var word;
var index;
var char;

if (position.generated(node)) {
return;
Expand All @@ -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);
Expand Down
6 changes: 6 additions & 0 deletions test/fixtures/carriage-returns.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
---
title: "Example #"
---
# Establishing an example #

Description.
Expand Down
6 changes: 6 additions & 0 deletions test/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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'
]);
});
});

/*
Expand Down

0 comments on commit 7e92656

Please sign in to comment.