PrismarineJS / prismarine-chat

A parser for a minecraft chat message
MIT License
34 stars 21 forks source link

format.js RangeError: Invalid string length #108

Closed Yaodeowo closed 6 months ago

Yaodeowo commented 6 months ago

return string.replace(/%(?:(\d+)\$)?(s|%)/g, (g0, g1) => { ^

RangeError: Invalid string length

Node.js v18.17.1

my fix code: module.exports = format

function format (string, _with = []) { let i = 0

return string.replace(/%(?:(\d+)\$)?(s|%)/g, (g0, g1) => { if (g0 === '%%') { return '%' const idx = g1 ? parseInt(g1) - 1 : i++ if (_with[idx] !== undefined && _with[idx].length !== undefined) { if (_with[idx].length > 5000) return ""; }; if (_with[idx] !== undefined) { return _with[idx] } else { return '' } } }) }

// i hope can add the limit

extremeheat commented 6 months ago

Dupe #106

Yaodeowo commented 5 months ago

Dupe #106

NAH