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

more strict String Parser regex #1554

Closed
FourwingsY opened this issue Jun 28, 2021 · 3 comments
Closed

more strict String Parser regex #1554

FourwingsY opened this issue Jun 28, 2021 · 3 comments

Comments

@FourwingsY
Copy link
Contributor

FourwingsY commented Jun 28, 2021

Describe the bug

from REGEX_PARSE = /^(\d{4})[-/]?(\d{1,2})?[-/]?(\d{0,2})[^0-9]*(\d{1,2})?:?(\d{1,2})?:?(\d{1,2})?[.:]?(\d+)?$/

when new Date('2020.05.23') is parsed in chrome2020-05-23T00:00:00.000, and Invalid in safari.
but dayjs('2020.05.23') is parsing as 2020-01-01T05:00:00.023

Expected behavior

dayjs('2020.05.23') should fallback to native Date

Information

I think the problem is that [^0-9]* accepts any characters including .
what commonly used cases are [Tt\s]*, and it seems okay to me.

@iamkun
Copy link
Owner

iamkun commented Jun 28, 2021

would you like to submit a PR with unit test to fix this?

@FourwingsY
Copy link
Contributor Author

I have found that dots are not a valid rule from ISO8601 or things, but it just worked in Chrome only.
So It means, It should not matched in REGEX, and fallback to Date

@FourwingsY
Copy link
Contributor Author

Fix merged

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

2 participants