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

check empty: true in string rule. Fixes #283 #284

Merged
merged 1 commit into from
Feb 8, 2022
Merged

check empty: true in string rule. Fixes #283 #284

merged 1 commit into from
Feb 8, 2022

Conversation

icebob
Copy link
Owner

@icebob icebob commented Feb 7, 2022

const schema = {
	status: {
		type: "string",
		uppercase: true,
		enum: ["a", "b", "c"],
		empty: true
	}
};

const check = v.compile(schema);
const obj = { status: "" };

console.log(check(obj), obj);

@icebob icebob requested a review from erfanium February 7, 2022 21:14
@icebob icebob linked an issue Feb 7, 2022 that may be closed by this pull request
Copy link
Collaborator

@erfanium erfanium left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I don't know why empty strings should be a valid value for enums when we can use null instead. btw the code looks good to me

@erfanium
Copy link
Collaborator

erfanium commented Feb 7, 2022

@icebob Also make sure schema.empty is false by default. this behavior should not be the default behavior for enums

@icebob icebob merged commit 65f3994 into master Feb 8, 2022
@icebob icebob deleted the issue-283 branch February 8, 2022 20:43
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Possible bug: Optional enum string fails validation on empty input
2 participants