Skip to content

Commit 984f578

Browse files
committed
fix: Corner case failure in error pretty-printer
1 parent 443e3aa commit 984f578

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

src/errors.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -91,7 +91,7 @@ export const prettifyError =
9191
let count = 1
9292
const end = error.linePos[1]
9393
if (end && end.line === line && end.col > col) {
94-
count = Math.min(end.col - col, 80 - ci)
94+
count = Math.max(1, Math.min(end.col - col, 80 - ci))
9595
}
9696
const pointer = ' '.repeat(ci) + '^'.repeat(count)
9797
error.message += `:\n\n${lineStr}\n${pointer}\n`

tests/doc/errors.js

+6
Original file line numberDiff line numberDiff line change
@@ -341,6 +341,12 @@ describe('pretty errors', () => {
341341
const doc = YAML.parseDocument(src, { prettyErrors: true })
342342
expect(doc.warnings).toMatchObject([{ name: 'YAMLWarning' }])
343343
})
344+
345+
test('repeated CR', () => {
346+
const src = '[' + '\r'.repeat(80)
347+
const doc = YAML.parseDocument(src, { prettyErrors: true })
348+
expect(doc.errors[0]).not.toHaveProperty('source')
349+
})
344350
})
345351

346352
describe('tags on invalid nodes', () => {

0 commit comments

Comments
 (0)