Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: isHexColor doesn't validate correctly #2566

Open
TrNgTien opened this issue Dec 18, 2024 · 0 comments
Open

fix: isHexColor doesn't validate correctly #2566

TrNgTien opened this issue Dec 18, 2024 · 0 comments
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.

Comments

@TrNgTien
Copy link

TrNgTien commented Dec 18, 2024

Description

By passing the string is 6633FF that the regex to verify hex color can bypass this validation.

I saw the problem that the validate can be pass with the string about from the regex from the source base of this repository validator.js

Minimal code-snippet showcasing the problem

This is the code from validator.js, that maybe the root cause of this validation.

https://github.com/validatorjs/validator.js/blob/master/src/lib/isHexColor.js

import assertString from './util/assertString';

const hexcolor = /^#?([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;

export default function isHexColor(str) {
  assertString(str);
  return hexcolor.test(str);
}

I think the regex should be implement like this

const hexcolor = /^#{1}([0-9A-F]{3}|[0-9A-F]{4}|[0-9A-F]{6}|[0-9A-F]{8})$/i;

Expected behavior

It should validate the string 6633FF is false
image
image

Actual behavior

It validate the string 6633FF is a hex color string
image

@TrNgTien TrNgTien added status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature. labels Dec 18, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature.
Development

No branches or pull requests

1 participant