dreamyguy / validate-color

✅🌈🙌 Validate HTML colors by 'name', 'special name', 'hex', 'rgb', 'rgba', 'hsl', 'hsla', 'hwb' or 'lab' values
https://www.npmjs.com/package/validate-color
MIT License
53 stars 6 forks source link

False positives with `rgb`, `rgba`, `hsl` and `hsla` values #3

Closed Cherry closed 4 years ago

Cherry commented 4 years ago

Firstly, thanks for this module. I was about to write my own colour validation for https://placeholders.dev before stumbling across this. 👍

However, it seems that there are some false positives with RGB, etc. values:

validateColor('rgba(255,255,255,1)'); // true
validateColor('rgba(255,255,255,1)dsadasda'); // true

This can also be replicated for rgb, hsl and hsla values.

Cherry commented 4 years ago

Taking a brief look at the code, I think it should be as simple as adding an end-of-string $ character to the end of the regex at https://github.com/dreamyguy/validate-color/blob/c84d8a010cd07365103be6e157056c250ef42819/src/validate-color/index.js#L167