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

* returns extra falsey values at the level of the wildcard #11

Open
ALawliet opened this issue May 28, 2015 · 4 comments
Open

* returns extra falsey values at the level of the wildcard #11

ALawliet opened this issue May 28, 2015 · 4 comments

Comments

@ALawliet
Copy link

> obj
{ 
    foo: { 
        bar: { 
            qux: 'asdf' 
        },
        baz: null,
        ping: 'pong' 
    } 
}

> mask(obj,'foo/*/qux')
{ 
    foo: { 
        bar: { 
            qux: 'asdf' 
        },
        baz: null
    } 
}

Is this intended? I was expecting:

{ 
    foo: { 
        bar: { 
            qux: 'asdf' 
        }
    } 
}
@nemtsov
Copy link
Owner

nemtsov commented May 29, 2015

Thanks for reporting this. I'd expect the same result as you (without baz: null). I'll look into it.

@yckart
Copy link

yckart commented Dec 14, 2016

Quick and dirty fix...

if (!util.has(ret, retKey)) continue

@@ -35,5 +35,6 @@
for (retKey in ret) {
  if (!util.has(ret, retKey)) continue
+ if (util.isEmpty(ret[retKey])) continue
  maskedObj[retKey] = ret[retKey]
}

@nemtsov
Copy link
Owner

nemtsov commented Dec 14, 2016

@yckart thank you for your contribution. If you're interested in making the code above into a PR with the change and test, I'll review and merge it asap.

@yckart
Copy link

yckart commented Dec 14, 2016

@nemtsov But I'm not sure, what's falsey?

null

...are empty arrays/objects/strings "empty values" too?

[]
{}
""

...and those?

[null, ""]
[ , , , ]
" "

wmakeev added a commit to wmakeev/json-mask that referenced this issue Feb 27, 2017
- add `compiledMask` argument validation
- add support for overlapped fields (related with nemtsov#16)
- fix: filter should return null if `obj` argument is not Array or PlainObject
- fix: wildcard `*` bug (nemtsov#11)
- fix: extra fields with falsy values in masked object (nemtsov#16)
- remove `util.has` from for..in loops (internal used objects have no iterable fields in prototypes)
- remove `util.isEmpty` from test for empty Array
@nemtsov nemtsov removed the bug label Oct 30, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants