Validate errorInfo.fixInfo object/properties in extension calls to onError.

This commit is contained in:
David Anson 2019-09-14 13:39:27 -07:00
parent 5895ea62cb
commit 65f6d38978
3 changed files with 95 additions and 22 deletions

View file

@ -382,6 +382,37 @@ function lintContent(
lines[errorInfo.lineNumber - 1].length))) {
throwError("range");
}
const fixInfo = errorInfo.fixInfo;
if (fixInfo) {
if (!helpers.isObject(fixInfo)) {
throwError("fixInfo");
}
if ((fixInfo.lineNumber !== undefined) &&
(!helpers.isNumber(fixInfo.lineNumber) ||
(fixInfo.lineNumber < 1) ||
(fixInfo.lineNumber > lines.length))) {
throwError("fixInfo.lineNumber");
}
const effectiveLineNumber = fixInfo.lineNumber || errorInfo.lineNumber;
if ((fixInfo.editColumn !== undefined) &&
(!helpers.isNumber(fixInfo.editColumn) ||
(fixInfo.editColumn < 1) ||
(fixInfo.editColumn >
lines[effectiveLineNumber - 1].length + 1))) {
throwError("fixInfo.editColumn");
}
if ((fixInfo.deleteCount !== undefined) &&
(!helpers.isNumber(fixInfo.deleteCount) ||
(fixInfo.deleteCount < -1) ||
(fixInfo.deleteCount >
lines[effectiveLineNumber - 1].length))) {
throwError("fixInfo.deleteCount");
}
if ((fixInfo.insertText !== undefined) &&
!helpers.isString(fixInfo.insertText)) {
throwError("fixInfo.insertText");
}
}
errors.push({
"lineNumber": errorInfo.lineNumber + frontMatterLines.length,
"detail": errorInfo.detail || null,