enesser / vCards-js

Create vCards to import contacts into Outlook, iOS, Mac OS, and Android devices from your website or application.
MIT License
426 stars 156 forks source link

Don't use new Array() #27

Closed adius closed 6 years ago

adius commented 6 years ago

If somebody (me) stores e.g. the cellPhone as a number, it will crash the whole formatter. (https://github.com/enesser/vCards-js/blob/master/lib/vCardFormatter.js#L223) as it means you're trying to generate an array with a certain size which can lead to errors if the range is too large.

E.g. new Array(12345678900) will throw following error:

RangeError: Invalid array length
    at Object.getFormattedString (/Project/node_modules/vcards-js/lib/vCardFormatter.js:254:39)
    at Object.getFormattedString (/Project/node_modules/vcards-js/index.js:321:35)
    ...

So vCard.cellPhone = new Array(vCard.cellPhone); should be replaced with vCard.cellPhone = [vCard.cellPhone];

enesser commented 6 years ago

Thank you! Added to next version.