Describe the bug
With { allowSpaces: true }, isRgbColor removes whitespace inside numeric values and accepts malformed RGB/RGBA strings. For example, the first channel in rgb(2 55,0,0) is treated as 255.
Reproduction
const validator = require('validator');
for (const value of [
'rgb(2 55,0,0)',
'rgba(0,0,0,0. 5)',
'rgb(25 %,0%,0%)',
]) {
console.log(value, validator.isRgbColor(value, { allowSpaces: true }));
}
All three calls return true. The expected result is false: each channel or alpha value must form a contiguous numeric token, and a percentage sign must immediately follow its number. Whitespace around comma-separated values, such as rgb( 255 , 0 , 0 ), should remain supported.
The allowSpaces branch in src/lib/isRgbColor.js strips every whitespace character before checking the numeric patterns. A regression test covering these inputs fails on the current source.
Environment
- validator.js 13.15.35; also reproduced from
master at 9ff342479591ca5a43cb30000195bcf55c1bbed9
- Node.js 24.16.0
- Windows
Prepared with OpenAI Codex. The reproduction and regression test were run locally.
Describe the bug
With
{ allowSpaces: true },isRgbColorremoves whitespace inside numeric values and accepts malformed RGB/RGBA strings. For example, the first channel inrgb(2 55,0,0)is treated as255.Reproduction
All three calls return
true. The expected result isfalse: each channel or alpha value must form a contiguous numeric token, and a percentage sign must immediately follow its number. Whitespace around comma-separated values, such asrgb( 255 , 0 , 0 ), should remain supported.The
allowSpacesbranch insrc/lib/isRgbColor.jsstrips every whitespace character before checking the numeric patterns. A regression test covering these inputs fails on the current source.Environment
masterat9ff342479591ca5a43cb30000195bcf55c1bbed9Prepared with OpenAI Codex. The reproduction and regression test were run locally.