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

get of nonexistent path returns value of parent if it's a falsy value #22

Open
andrewwalters opened this issue Sep 18, 2023 · 1 comment

Comments

@andrewwalters
Copy link

andrewwalters commented Sep 18, 2023

Do you want to request a feature or report a bug?

Bug

What is the current behavior?

If a get is performed with a non-existent path, and a parent of the path does exist and is a falsy value, then that value is returned instead of undefined.

If the current behavior is a bug, please provide the steps to reproduce.
What is the expected behavior?

From the node REPL:

> mpath.get('x.y', { x: 0 })
0 // Expect: undefined
> mpath.get('x.y', { x: false })
false // Expect: undefined
> mpath.get('x.y', { x: null })
null // Expect: undefined
> mpath.get('x.y', { x: 1 })
undefined // Ok
> mpath.get('x.y', { x: { y: 'z' } })
'z' // Ok

What are the versions of Node.js and mpath are you are using? Note that "latest" is not a version.

node 16.19.0
mpath 0.9.0

@andrewwalters
Copy link
Author

andrewwalters commented Sep 18, 2023

I've also noticed the following when attempting to index into a string:

> o = { x: 'abcde' }
{ x: 'abcde' }
> mpath.get('x.3', o)
'd'

Although here, I'm not sure what the expected behavior is. On the one hand, mpath.has('x.3', o) returns false, so I'd expect that get should return undefined. On the other hand, o.x[3] gives d.

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