Skip to content

Updated regexp for more robust ISO 8601 validation#656

Closed
bricss wants to merge 10 commits intohapijs:masterfrom
bricss:master
Closed

Updated regexp for more robust ISO 8601 validation#656
bricss wants to merge 10 commits intohapijs:masterfrom
bricss:master

Conversation

@bricss
Copy link
Contributor

@bricss bricss commented May 25, 2015

Updated regexp for more robust ISO 8601 validation -> https://regex101.com/r/wA4cE0/1

@bricss bricss changed the title Updated regexp for absolute ISO 8601 date validation Updated regexp for more robust ISO 8601 validation May 26, 2015
Copy link
Contributor

Choose a reason for hiding this comment

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

It looks like you've fundamentally changed some of the old tests why not just create new ones? Since this library is used across many projects we should make sure it functions like it used to as well as for the new functionality.

Copy link
Collaborator

Choose a reason for hiding this comment

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

This indeed changes the test too much, you basically removed the regexp from the equation.

@bricss
Copy link
Contributor Author

bricss commented May 26, 2015

Yep, it has some breaking changes in ISO 8601 validation, because current implementation do not cover full spec and some valid ISO 8601 dates do not pass validation. But I will add new test, its my bad.

@Marsup Marsup added the bug Bug or defect label Jun 6, 2015
@Marsup Marsup added this to the 6.5.0 milestone Jun 6, 2015
@Marsup Marsup self-assigned this Jun 6, 2015
@Marsup
Copy link
Collaborator

Marsup commented Jun 6, 2015

I'd like to include that in 6.5.0, do you need anything to get this moving ?

@bricss
Copy link
Contributor Author

bricss commented Jun 6, 2015

I will add more tests today to cover all cases.

@bricss
Copy link
Contributor Author

bricss commented Jun 6, 2015

Done.

@Marsup
Copy link
Collaborator

Marsup commented Jun 7, 2015

1st thing, I've improved your regexp with non-capturing groups, twice the performance (/^(?:\d{4}(?!\d{2}\b))(?:(-?)(?:(?:0[1-9]|1[0-2])(?:\1(?:[12]\d|0[1-9]|3[01]))?|W(?:[0-4]\d|5[0-2])(?:-?[1-7])?|(?:00[1-9]|0[1-9]\d|[12]\d{2}|3(?:[0-5]\d|6[1-6])))(?![T]$|[T][\d]+Z$)(?:[T\s](?:(?:(?:[01]\d|2[0-3])(?:(:?)[0-5]\d)?|24\:?00)(?:[.,]\d+(?!:))?)(?:\2[0-5]\d(?:[.,]\d+)?)?(?:[Z]|(?:[+-])(?:[01]\d|2[0-3])(?::?[0-5]\d)?)?)?)?$/)

2nd, some of the strings pass (eg. 2013-06-07T23) that shouldn't.

@bricss
Copy link
Contributor Author

bricss commented Jun 7, 2015

Ok, I will add this changes.

@bricss
Copy link
Contributor Author

bricss commented Jun 8, 2015

I've tried your regexp and something went wrong, many date's now isn't passing validation -> https://regex101.com/r/rL6eJ5/1

@Marsup
Copy link
Collaborator

Marsup commented Jun 8, 2015

Used without any side effect on joi's tests.

@bricss
Copy link
Contributor Author

bricss commented Jun 8, 2015

I've just replace regexp in my fork and now 16 tests failing.

@Marsup
Copy link
Collaborator

Marsup commented Jun 8, 2015

Probably the markdown formatting, I've updated the comment to hopefully skip it, try again.

@bricss
Copy link
Contributor Author

bricss commented Jun 8, 2015

Yep, now everything works like a charm, updated regexp & tests to bypass "2013-06-07T23" -> https://regex101.com/r/hB9vV0/1

@Marsup
Copy link
Collaborator

Marsup commented Jun 9, 2015

I think you can revert many changes you did to the tests, the goal is to test the mix of constraints, not add "yes-constraints", this is testing the same thing over and over.

@bricss
Copy link
Contributor Author

bricss commented Jun 10, 2015

Ok, will fix that.

@bricss
Copy link
Contributor Author

bricss commented Jun 17, 2015

Do we need some additional changes to get this merged?

@Marsup
Copy link
Collaborator

Marsup commented Jun 17, 2015

The previous comment still stands.

@bricss
Copy link
Contributor Author

bricss commented Jun 21, 2015

Finally removed the unnecessary tests.

@manonthemat
Copy link

Looking forward to see this get merged in 👍

Marsup added a commit that referenced this pull request Jun 24, 2015
@Marsup
Copy link
Collaborator

Marsup commented Jun 24, 2015

Merged and fixed, sorry the back and forth wasn't working.

@Marsup Marsup closed this Jun 24, 2015
@lock
Copy link

lock bot commented Jan 9, 2020

This thread has been automatically locked due to inactivity. Please open a new issue for related bugs or questions following the new issue template instructions.

@lock lock bot locked as resolved and limited conversation to collaborators Jan 9, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

bug Bug or defect

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants