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

pluck() doesn't handle properties that contain a "." #26

Open
chudley opened this issue Dec 15, 2017 · 0 comments
Open

pluck() doesn't handle properties that contain a "." #26

chudley opened this issue Dec 15, 2017 · 0 comments

Comments

@chudley
Copy link

chudley commented Dec 15, 2017

When using pluck() against an object whose properties contain "." characters (e.g. IP addresses) anywhere before the end of traversal, pluck() will return "undefined":

> var o = { '1.2.3.4': { 'prop': true }, 'test': { 'prop': true } };
undefined
> jsprim.pluck(o, 'test.prop');
true
> jsprim.pluck(o, '1.2.3.4');
{ prop: true }
> jsprim.pluck(o, '1.2.3.4.prop');
undefined

In the case where the object at the end of traversal has my example IP address key, it works:

> var o = { 'a': { 'b': { '1.2.3.4': true } } };
undefined
> jsprim.pluck(o, 'a.b.1.2.3.4');
true

This is fairly expected given the ambiguity around object traversal in this case, and I'm honestly not sure how to handle this particular case other than documentation. Perhaps pluck() could be expanded to take an Array of keys that it will work through? Something like:

jsprim.pluck(obj, [ '1.2.3.4', 'prop' ]);

For a real-world example of this, our ManateeClusterDetails class will populate pgs_peers with an object containing the cluster's peers indexed on the peer ID, which we currently set as the IP:PORT of postgres (see here). I was programatically using the ID as part of the key to pluck from this object, and it took me a little digging to figure out that pluck() substr's through the "." characters it finds to perform traversal, and that the keys I was putting together were problematic.

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