-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
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: escape last period to match only milliseconds (#1239) #1295
Conversation
Codecov Report
@@ Coverage Diff @@
## dev #1295 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 174 174
Lines 1672 1672
Branches 382 382
=========================================
Hits 1672 1672
Continue to review full report at Codecov.
|
Can you add some test case please ? like https://github.com/iamkun/dayjs/blob/dev/test/parse.test.js#L138 |
includes two tests that would have matched before fix iamkun#1239 but no longer match
Added some test cases. The regular expression can still get in trouble accepting odd strings like |
LGTM |
we should only match the last But not as a wildcard, this would cause some bug in |
# [1.10.0](v1.9.8...v1.10.0) (2021-01-03) ### Bug Fixes * add ordinal to localeData plugin ([#1266](#1266)) ([fd229fa](fd229fa)) * add preParsePostFormat plugin & update Arabic [ar] locale ([#1255](#1255)) ([f2e4790](f2e4790)) * add type support for plural forms of units ([#1289](#1289)) ([de49bb1](de49bb1)) * escape last period to match only milliseconds ([#1239](#1239)) ([#1295](#1295)) ([64037e6](64037e6)) ### Features * add ES6 Module Support, package.json module point to "esm/index.js" ([#1298](#1298)) ([f63375d](f63375d)), closes [#598](#598) [#313](#313)
# [1.10.0](iamkun/dayjs@v1.9.8...v1.10.0) (2021-01-03) ### Bug Fixes * add ordinal to localeData plugin ([#1266](iamkun/dayjs#1266)) ([fd229fa](iamkun/dayjs@fd229fa)) * add preParsePostFormat plugin & update Arabic [ar] locale ([#1255](iamkun/dayjs#1255)) ([f2e4790](iamkun/dayjs@f2e4790)) * add type support for plural forms of units ([#1289](iamkun/dayjs#1289)) ([de49bb1](iamkun/dayjs@de49bb1)) * escape last period to match only milliseconds ([#1239](iamkun/dayjs#1239)) ([#1295](iamkun/dayjs#1295)) ([64037e6](iamkun/dayjs@64037e6)) ### Features * add ES6 Module Support, package.json module point to "esm/index.js" ([#1298](iamkun/dayjs#1298)) ([f63375d](iamkun/dayjs@f63375d)), closes [#598](iamkun/dayjs#598) [#313](iamkun/dayjs#313)
# [1.10.0](iamkun/dayjs@v1.9.8...v1.10.0) (2021-01-03) ### Bug Fixes * add ordinal to localeData plugin ([#1266](iamkun/dayjs#1266)) ([fd229fa](iamkun/dayjs@fd229fa)) * add preParsePostFormat plugin & update Arabic [ar] locale ([#1255](iamkun/dayjs#1255)) ([f2e4790](iamkun/dayjs@f2e4790)) * add type support for plural forms of units ([#1289](iamkun/dayjs#1289)) ([de49bb1](iamkun/dayjs@de49bb1)) * escape last period to match only milliseconds ([#1239](iamkun/dayjs#1239)) ([#1295](iamkun/dayjs#1295)) ([64037e6](iamkun/dayjs@64037e6)) ### Features * add ES6 Module Support, package.json module point to "esm/index.js" ([#1298](iamkun/dayjs#1298)) ([f63375d](iamkun/dayjs@f63375d)), closes [#598](iamkun/dayjs#598) [#313](iamkun/dayjs#313)
# [1.10.0](iamkun/dayjs@v1.9.8...v1.10.0) (2021-01-03) ### Bug Fixes * add ordinal to localeData plugin ([#1266](iamkun/dayjs#1266)) ([fd229fa](iamkun/dayjs@fd229fa)) * add preParsePostFormat plugin & update Arabic [ar] locale ([#1255](iamkun/dayjs#1255)) ([f2e4790](iamkun/dayjs@f2e4790)) * add type support for plural forms of units ([#1289](iamkun/dayjs#1289)) ([de49bb1](iamkun/dayjs@de49bb1)) * escape last period to match only milliseconds ([#1239](iamkun/dayjs#1239)) ([#1295](iamkun/dayjs#1295)) ([64037e6](iamkun/dayjs@64037e6)) ### Features * add ES6 Module Support, package.json module point to "esm/index.js" ([#1298](iamkun/dayjs#1298)) ([f63375d](iamkun/dayjs@f63375d)), closes [#598](iamkun/dayjs#598) [#313](iamkun/dayjs#313)
fix #1239
To be sure the last digit token in REGEX_PARSE only matches for milliseconds, the period must be escaped. Otherwise, it acts as a wildcard.
All of these are the same date/time using different ISO 8601 time zone formats:
dayjs("2020-12-31T18:00:00.000-0500")
dayjs("2020-12-31T18:00:00-05:00")
dayjs("2020-12-31T18:00:00-0500")
The first two parse correctly because REGEX_PARSE doesn't match. But the last example does match REGEX_PARSE, with the final
-
character matching the wildcard. So the date is parsed in local time and the first three characters of 0500 become 50ms.