Skip to content

Commit

Permalink
Merge pull request #20 from appcelerator/timob-12167
Browse files Browse the repository at this point in the history
[TIMOB-12167] Fixed plist parsing when <string> tag is empty.
  • Loading branch information
Bryan Hughes committed Jan 14, 2013
2 parents 849e774 + 24621a2 commit db0b3c2
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 9 deletions.
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
0.1.X
-------------------
* Fixed plist parsing when <string> tag is empty [TIMOB-12167]

0.1.25 (12/21/2012)
-------------------
* Fixed buffer size issues when ios library detects installed developer certs [TIMOB-12146]
Expand Down
18 changes: 9 additions & 9 deletions lib/plist.js
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ function walkDict(obj, node) {

while (node) {
if (node.nodeType == xml.ELEMENT_NODE && node.tagName == 'key') {
key = (node.firstChild.data || '').trim();
key = (node.firstChild && node.firstChild.data || '').trim();

next = node.nextSibling;
while (next && next.nodeType != xml.ELEMENT_NODE) {
Expand All @@ -88,16 +88,16 @@ function walkDict(obj, node) {
obj[key] = false;
node = next;
} else if (next.tagName == 'string') {
obj[key] = '' + (next.firstChild.data || '').trim(); // cast all values as strings
obj[key] = '' + (next.firstChild && next.firstChild.data || '').trim(); // cast all values as strings
node = next;
} else if (next.tagName == 'integer') {
obj[key] = parseInt(next.firstChild.data) || 0;
obj[key] = parseInt(next.firstChild && next.firstChild.data) || 0;
node = next;
} else if (next.tagName == 'real') {
obj[key] = parseFloat(next.firstChild.data) || 0;
obj[key] = parseFloat(next.firstChild && next.firstChild.data) || 0;
node = next;
} else if (next.tagName == 'date') {
var d = (next.firstChild.data || '').trim();
var d = (next.firstChild && next.firstChild.data || '').trim();
obj[key] = d ? new Date(d) : null; // note: toXml() can't convert a null date back to a <date> tag
node = next;
} else if (next.tagName == 'array') {
Expand All @@ -117,11 +117,11 @@ function walkArray(arr, node) {
if (node.nodeType == xml.ELEMENT_NODE) {
switch (node.tagName) {
case 'string':
arr.push('' + (node.firstChild.data || '').trim());
arr.push('' + (node.firstChild && node.firstChild.data || '').trim());
break;

case 'integer':
arr.push(parseInt(node.firstChild.data) || 0);
arr.push(parseInt(node.firstChild && node.firstChild.data) || 0);
break;

case 'array':
Expand All @@ -131,7 +131,7 @@ function walkArray(arr, node) {
break;

case 'date':
var d = (node.firstChild.data || '').trim();
var d = (node.firstChild && node.firstChild.data || '').trim();
arr.push(d ? new Date(d) : null);
break;

Expand All @@ -142,7 +142,7 @@ function walkArray(arr, node) {
break;

case 'data':
arr.push((node.firstChild.data || '').replace(/\s*/g, ''));
arr.push((node.firstChild && node.firstChild.data || '').replace(/\s*/g, ''));
}
}
node = node.nextSibling;
Expand Down

0 comments on commit db0b3c2

Please sign in to comment.