Fix possible array-out-of-bounds access, add test.

This commit is contained in:
David Anson 2015-07-22 23:17:08 -07:00
parent 7f5dd9ab6b
commit a958a33860
2 changed files with 25 additions and 1 deletions

View file

@ -65,7 +65,7 @@ function lintContent(content, config) {
token.line = lines[token.map[0]];
token.lineNumber = token.map[0] + 1;
// Trim bottom of token to exclude whitespace lines
while (!(lines[token.map[1] - 1].trim())) {
while (token.map[1] && !(lines[token.map[1] - 1].trim())) {
token.map[1]--;
}
// Annotate children with lineNumber

View file

@ -189,6 +189,30 @@ module.exports.stringInputLineEndings = function stringInputLineEndings(test) {
});
};
module.exports.inputOnlyNewline = function inputOnlyNewline(test) {
test.expect(2);
var options = {
"strings": {
"cr": "\r",
"lf": "\n",
"crlf": "\r\n"
},
"config": {
"default": false
}
};
markdownlint(options, function callback(err, actualResult) {
test.ifError(err);
var expectedResult = {
"cr": {},
"lf": {},
"crlf": {}
};
test.deepEqual(actualResult, expectedResult, "Undetected issues.");
test.done();
});
};
module.exports.defaultTrue = function defaultTrue(test) {
test.expect(2);
var options = {