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

Unexpected false-positive case when validating January 1st, Year 1 (01-01-0001) #180

Open
emfloyd2 opened this issue Feb 6, 2023 · 0 comments

Comments

@emfloyd2
Copy link

emfloyd2 commented Feb 6, 2023

Hello,

We ran into an unexpected issue with our Ozzo validation code (which was allowing January 1st, Year 1 to bypass our date validation).

Please see snippet below - is this a case of user error, or bug?

package main

import (
	"fmt"
	ozzo_validation "github.com/go-ozzo/ozzo-validation/v4"
	"time"
)

func main() {
	// This date shouldn't pass validation! But it does >_<
	//
	// dob in this case is less than minDob
	dob := time.Date(1, time.Month(1), 1, 0, 0, 0, 0, time.UTC)
	minDob := ozzo_validation.Min(time.Date(1900, 1, 1, 0, 0, 0, 0, time.UTC))
	if err := ozzo_validation.Validate(
		dob,
		minDob,
	); err != nil {
		fmt.Println(err)
	} else {
		fmt.Println("No failures!")
	}

}

It appears to be specific to a dob value of time.Date(1, time.Month(1), 1, 0, 0, 0, 0, time.UTC)

If we add at least one nanosecond to DOB value of January 1st, Year 1 - Ozzo Validation correctly rejects invalid date

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

No branches or pull requests

1 participant