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: option is not passed to validator in @IsDateString decorator #1061

Closed
GCastilho opened this issue May 5, 2021 · 7 comments
Closed

fix: option is not passed to validator in @IsDateString decorator #1061

GCastilho opened this issue May 5, 2021 · 7 comments
Labels
status: done/released Issue has been completed, no further action is needed. type: fix Issues describing a broken feature.

Comments

@GCastilho
Copy link

Description

According to the type docs, when using IsDateString({ strict: true}):
"If strict is true, performs additional checks for valid dates, e.g. invalidates dates like 2009-02-29". But those dates appear to be passing the validation in my app

Minimal code-snippet showcasing the problem
So I created a repo for bug reproduction here. In essence:

class ValidatorTest {
	@IsDateString({ strict: true })
	isoDate: string
}

const instance = new ValidatorTest()
instance.isoDate = '2009-02-29'

await assert.rejects(() => validateOrReject(instance), 'Class successfully validated') // <<<< Fails

Expected behavior

According to the docs, a date as "2009-02-29" should fail when using isoDate validation with strict = true; (taken directly from the docs)

Actual behavior

The validator passes

Version

class-validator: 0.13.1
node: 14

@GCastilho GCastilho added status: needs triage Issues which needs to be reproduced to be verified report. type: fix Issues describing a broken feature. labels May 5, 2021
@hakimio
Copy link
Contributor

hakimio commented May 25, 2021

Same issue here. Seems to be an issue with class-validator itself, not validator.js it's using.
Following code works as expected with validator.js:

const validator = require('validator');

validator.isISO8601('2009-02-29', {strict: true});

https://runkit.com/hakimio/60aca6995be746001af0ca45

@hakimio
Copy link
Contributor

hakimio commented May 26, 2021

Ok, found the bug here. Unlike IsISO8601, IsDateString doesn't send the options object to the validator.

Line 27 should be changed to the following in IsDateString.ts:

validate: (value, args): boolean => isDateString(value, args.constraints[0])

Current workaround would be to use IsISO8601 instead of IsDateString.

@NoNameProvided do you want me to create a new PR or can you just fix this?

hakimio added a commit to hakimio/class-validator that referenced this issue May 26, 2021
`@IsDateString({strict: true})` doesn't work because options are not passed to the validator.

Fixes typestack#1061
@hakimio
Copy link
Contributor

hakimio commented May 26, 2021

PR #1097

@thenbe
Copy link

thenbe commented Jul 30, 2022

Related: validatorjs/validator.js#2003

@NoNameProvided NoNameProvided added status: has PR Issues which has a related PR closing the issue. status: fixed Issues with merged PRs, but not released yet. and removed status: needs triage Issues which needs to be reproduced to be verified report. status: has PR Issues which has a related PR closing the issue. labels Nov 20, 2022
@NoNameProvided
Copy link
Member

Merged in #1720.

@NoNameProvided NoNameProvided changed the title fix: There might be a bug in IsISO8601/IsDateString in strict mode fix: option is not passed to validator in @IsDateString decorator Nov 20, 2022
@NoNameProvided NoNameProvided added status: done/released Issue has been completed, no further action is needed. and removed status: fixed Issues with merged PRs, but not released yet. labels Dec 9, 2022
@NoNameProvided
Copy link
Member

This feature/fix has been released in 0.14.0.

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jan 10, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
status: done/released Issue has been completed, no further action is needed. type: fix Issues describing a broken feature.
Development

Successfully merging a pull request may close this issue.

4 participants