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

dayjs(null) throws error, not return dayjs object as invalid date #2095

Closed
inqbs opened this issue Oct 25, 2022 · 4 comments · Fixed by #2175
Closed

dayjs(null) throws error, not return dayjs object as invalid date #2095

inqbs opened this issue Oct 25, 2022 · 4 comments · Fixed by #2175
Labels

Comments

@inqbs
Copy link

inqbs commented Oct 25, 2022

Describe the bug
dayjs(null) is throws error, 'Uncaught TypeError: can't access property "constructor", n is null'.
It says that error occured on dayjs/plugin/objectSupport.js

11:11:19.151 objectSupport.js:1 Uncaught TypeError: Cannot read properties of null (reading 'constructor')
    at M.r (objectSupport.js:1:412)
    at i.parse (objectSupport.js:1:887)
    at e.parse (preParsePostFormat.js:1:447)
    at u.parse (utc.js:1:692)
    at new M (dayjs.min.js:1:2038)
    at w (dayjs.min.js:1:1869)
    at <anonymous>:1:1
r @ objectSupport.js:1
i.parse @ objectSupport.js:1
e.parse @ preParsePostFormat.js:1
u.parse @ utc.js:1
M @ dayjs.min.js:1
w @ dayjs.min.js:1

Expected behavior
It should be return dayjs object with invalid date. (it means, dayjs(null).isValid() return false correctly.)

Information

  • Day.js Version: v1.11.6
  • OS: Windows 10
  • Browser: Firefox latest version
  • Time zone: GMT+09:00
  • Used Plugins:
    • customParseFormat
    • duration
    • isoWeek
    • isSameOrBefore
    • objectSupport
@knitevision1
Copy link

knitevision1 commented Oct 28, 2022

+1 to this one

Was also affected by this when date passed to dayjs instance is null
Looks like introduced in v1.11.6 here

As a workaround - introduced a nullish check.

@lleger
Copy link

lleger commented Nov 11, 2022

We ran into this today as well. Passed a null, got an unexpected exception. We wrapped it with a null check, but it would be good to update the typing!

@illjah42
Copy link
Contributor

+1
This is because of plugin objectSupport
new check in isObject function throws if null is passed

c9370ea#r87477073

@github-actions
Copy link

github-actions bot commented Jul 1, 2023

🎉 This issue has been resolved in version 1.11.9 🎉

The release is available on:

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants