guillaumepotier / validator.js

Powerful objects and strings validation in javascript for Node and the browser
http://validatorjs.org
MIT License
255 stars 39 forks source link

Fix wrong length for astral code points #52

Closed rplopes closed 5 years ago

rplopes commented 8 years ago

Because of the way Javascript deals with unicode characters, astral code points like some Chinese characters or emojis are marked as surrogate pairs, and are therefore counted as 2 separate characters:

> '👾'.length
2

This means that when using these characters, the limits in Length might not always be accurate.

This PR fixes that by identifying those astral symbols and replacing them with a simple unicode character (_). This solution was based on https://mathiasbynens.be/notes/javascript-unicode. Other solutions would require adding external dependencies.

ruimarinho commented 8 years ago

I consider this to be breaking change as we're effectively changing the return value for the astral symbols.

franciscocardoso commented 5 years ago

Deprecated.