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

isDate crashing on string of size 4 #2498

Open
NSchneiders opened this issue Nov 19, 2024 · 1 comment
Open

isDate crashing on string of size 4 #2498

NSchneiders opened this issue Nov 19, 2024 · 1 comment
Labels

Comments

@NSchneiders
Copy link

NSchneiders commented Nov 19, 2024

Describe the bug
I am using the isDate function of validator and when I use it on string of exactly size 4, it crashes.

Examples
Code line:
validator.isDate('test')

error code:
at Object.isDate (path-to-y-project\backend\node_modules\validator\lib\isDate.js:86:19)

Additional context
Validator.js version:
"node_modules/validator": {
"version": "13.12.0",
"resolved": "https://registry.npmjs.org/validator/-/validator-13.12.0.tgz",
"integrity": "sha512-****",
"license": "MIT",
"engines": {
"node": ">= 0.10"
}
},
Node.js version: Node.js v20.18.0
OS platform: windows

My current fix
.
.
.
dateObj[formatWord.charAt(0)] = dateWord;
}
} catch (err) {
_iterator.e(err);
} finally {
_iterator.f();
}
if (dateObj.y == null || dateObj.m == null || dateObj.d == null){
console.log("Modified by me");
return false;
}
var fullYear = dateObj.y;

// Check if the year starts with a hyphen
if (fullYear.startsWith('-')) {
  return false; // Hyphen before year is not allowed
}

.
.
.

I have just brute force the fix and it is probably terrible :)

@jamro
Copy link

jamro commented Dec 8, 2024

It seems to be duplicated with #2427 and fixed by #2443 .
I was able to reproduce the problem on 13.12.0, but it does not occur in the latest dev version.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants