The parseDocument
and parseAllDocuments
functions should never throw according to the documentation. However, when these functions are fed an invalid input with a lot (≥80) of carriage return characters (\r
), an exception is thrown, which originates in the prettifyError
function.
// reproduce.js
const yaml = require("yaml");
const string = "[" + "\r".repeat(80);
yaml.parseDocument(string);
$ yarn node reproduce.js
yarn node v1.22.19
/home/nazar/src/yaml-bug/node_modules/yaml/dist/errors.js:54
const pointer = ' '.repeat(ci) + '^'.repeat(count);
^
RangeError: Invalid count value
at String.repeat (<anonymous>)
at /home/nazar/src/yaml-bug/node_modules/yaml/dist/errors.js:54:46
at Array.forEach (<anonymous>)
at Object.parseDocument (/home/nazar/src/yaml-bug/node_modules/yaml/dist/public-api.js:54:20)
at Object.<anonymous> (/home/nazar/src/yaml-bug/reproduce.js:3:6)
at Module._compile (node:internal/modules/cjs/loader:1254:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1308:10)
at Module.load (node:internal/modules/cjs/loader:1117:32)
at Module._load (node:internal/modules/cjs/loader:958:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
Node.js v18.14.2