TooTallNate / plist.js

Mac OS X Plist parser/builder for Node.js and browsers
MIT License
584 stars 123 forks source link

simple bug: Inconsistencies around null and undefined #75

Open amaramth opened 8 years ago

amaramth commented 8 years ago

In code, plist.build({foo:undefined}) === plist.build({}) and plist.build({foo:null}) === plist.build(plist.parse(plist.build({foo:null}))) are not true and I think they should be.

exposition:

Javascript has null and undefined and [key missing]; JSON has null and [key missing]; plist has [key has no value] and [key missing]. I derive this from plist.build({foo:null}) !== plist.build({}), which is true and seems like it should be - this assumption might be false, though.

JSON.stringify,parse converts

plist.build,parse should do likewise, converting

Currently, it actually does

Can you reply with clarification? I don't know if that's the most consistent way to change this, or if it should be changed.

TooTallNate commented 8 years ago

👍 PR welcome

mreinstein commented 8 years ago

technically this would be an API change, so if you send a PR this would require bumping the major version on publish. Just putting this here as a reminder if/when that happens.

lordgreg commented 8 years ago

This i causing exactly the issue a-lot of Cordova users currently have:

Here is an example:

Cordova adds two keys with nullified values to plist, which plist reads them out:

  NSMainNibFile: null,
  'NSMainNibFile~ipad': null,

What plist (latest) is then doing is, it writes them back to plist (including all others possible options we write to config.xml). The objects above become:

    <key>NSMainNibFile</key>
    <value>NSMainNibFile~ipad</value>

Expected output:

--no output--

One option currently is to use the version 1.2.0 (yea, 1.2.0!) or, the hacky way to just remove both keys from plist "manually" from the string that plist module generates.

Both of them are totally wrong.

mreinstein commented 3 years ago

@amaramth I know this is a crazy-late reply, but I'm getting ready to start tackling a v4 of plist.js. If you're still interested in having this change go into a new major version, it's upcoming.