Skip to content

Commit

Permalink
fix: Corner case failure in error pretty-printer
Browse files Browse the repository at this point in the history
  • Loading branch information
eemeli committed Apr 24, 2023
1 parent ffdd2fb commit a67a019
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ export const prettifyError =
let count = 1
const end = error.linePos[1]
if (end && end.line === line && end.col > col) {
count = Math.min(end.col - col, 80 - ci)
count = Math.max(1, Math.min(end.col - col, 80 - ci))
}
const pointer = ' '.repeat(ci) + '^'.repeat(count)
error.message += `:\n\n${lineStr}\n${pointer}\n`
Expand Down
6 changes: 6 additions & 0 deletions tests/doc/errors.ts
Original file line number Diff line number Diff line change
Expand Up @@ -341,6 +341,12 @@ describe('pretty errors', () => {
const doc = YAML.parseDocument(src, { prettyErrors: true })
expect(doc.warnings).toMatchObject([{ name: 'YAMLWarning' }])
})

test('repeated CR', () => {
const src = '[' + '\r'.repeat(80)
const doc = YAML.parseDocument(src, { prettyErrors: true })
expect(doc.errors[0]).not.toHaveProperty('source')
})
})

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

0 comments on commit a67a019

Please sign in to comment.