diff --git a/lib/util/atomhandler.js b/lib/util/atomhandler.js index c98d7a41e..36a6fe71d 100644 --- a/lib/util/atomhandler.js +++ b/lib/util/atomhandler.js @@ -67,19 +67,22 @@ AtomHandler.prototype.parse = function (entityXml, innerTag) { } var propertiesXmlTag = this._xmlQualifyXmlTagName(innerTag, this.nsMeta); - if (entityXml.content && entityXml.content[propertiesXmlTag]) { for (var property in entityXml.content[propertiesXmlTag]) { - if (property !== Constants.XML_METADATA_MARKER) { - var propertyName = property; - if (property.indexOf(this.nsData) !== -1) { - propertyName = property.substr(2, property.length - 2); - } + var propertyName = property; + if (azureutil.stringStartsWith(propertyName, this.nsData + ':')) { + propertyName = property.substr(2, property.length - 2); + } + if (property !== Constants.XML_METADATA_MARKER) { if (azureutil.objectIsEmpty(entityXml.content[propertiesXmlTag][property])) { // Empty properties are represented as an empty string. entity[propertyName] = ''; - } else if (entityXml.content[propertiesXmlTag][property][Constants.XML_VALUE_MARKER]) { + } else if (entityXml.content[propertiesXmlTag][property][Constants.XML_METADATA_MARKER] !== undefined && + entityXml.content[propertiesXmlTag][property][Constants.XML_METADATA_MARKER][this._xmlQualifyXmlTagName('null', this.nsMeta)] && + entityXml.content[propertiesXmlTag][property][Constants.XML_METADATA_MARKER][this._xmlQualifyXmlTagName('null', this.nsMeta)] === 'true') { + entity[propertyName] = null; + } else if (entityXml.content[propertiesXmlTag][property][Constants.XML_VALUE_MARKER] !== undefined) { // Has an entry for value if (entityXml.content[propertiesXmlTag][property][Constants.XML_METADATA_MARKER] && entityXml.content[propertiesXmlTag][property][Constants.XML_METADATA_MARKER][this._xmlQualifyXmlTagName('type', this.nsMeta)]) { @@ -89,10 +92,6 @@ AtomHandler.prototype.parse = function (entityXml, innerTag) { propertyName, entityXml.content[propertiesXmlTag][property][Constants.XML_VALUE_MARKER], entityXml.content[propertiesXmlTag][property][Constants.XML_METADATA_MARKER][this._xmlQualifyXmlTagName('type', this.nsMeta)]); - } else if (entityXml.content[propertiesXmlTag][property][Constants.XML_METADATA_MARKER] && - entityXml.content[propertiesXmlTag][property][Constants.XML_METADATA_MARKER][this._xmlQualifyXmlTagName('null', this.nsMeta)] && - entityXml.content[propertiesXmlTag][property][Constants.XML_METADATA_MARKER][this._xmlQualifyXmlTagName('null', this.nsMeta)] === 'true') { - entity[propertyName] = null; } else { // The situation where a value marker exists and no type / null metadata marker exists shouldn't happen, but, just in case ... entity[propertyName] = entityXml.content[propertiesXmlTag][property][Constants.XML_VALUE_MARKER]; diff --git a/test/util/atomhandler-tests.js b/test/util/atomhandler-tests.js index ae8003e3f..0f7cc68a7 100644 --- a/test/util/atomhandler-tests.js +++ b/test/util/atomhandler-tests.js @@ -144,4 +144,103 @@ suite('atomhandler-tests', function () { done(); }); + + test('Parse', function (done) { + var atomHandler = new AtomHandler('m', 'd'); + + var entityXmlJs = { + title: '', + updated: '', + author: { + name: '' + }, + id: '', + content: { + '@': { + type: 'application/xml' + }, + 'm:properties': { + 'd:PartitionKey': 'part1', + 'd:RowKey': 'row1', + 'd:intValue': '10', + 'd:stringValue': 'my string', + 'd:nullValue': '', + 'd:nullValue2': null + } + } + }; + + var entityResult = atomHandler.parse(entityXmlJs); + + var entity = { + 'PartitionKey': 'part1', + 'RowKey': 'row1', + 'intValue': '10', + 'stringValue': 'my string', + 'nullValue': '', + 'nullValue2': '' + }; + + assert.deepEqual(entityResult, entity); + + done(); + }); + + test('ParseDataTypes', function (done) { + var atomHandler = new AtomHandler('m', 'd'); + + var entityXmlJs = { + title: '', + updated: '', + author: { + name: '' + }, + id: '', + content: { + '@': { + type: 'application/xml' + }, + 'm:properties': { + 'd:PartitionKey': { + '#': 'part1', + '@': { 'm:type': 'Edm.String' } + }, + 'd:RowKey': { + '#': 'row1', + '@': { 'm:type': 'Edm.String' } + }, + 'd:intValue': { + '#': '10', + '@': { 'm:type': 'Edm.Int32' } + }, + 'd:stringValue': { + '#': 'my string', + '@': { 'm:type': 'Edm.String' } + }, + 'd:nullValue': { + '#': '', + '@': { 'm:null': 'true' } + }, + 'd:nullValue2': { + '@': { 'm:null': 'true' } + } + } + } + }; + + var entityResult = atomHandler.parse(entityXmlJs); + + var entity = { + 'PartitionKey': 'part1', + 'RowKey': 'row1', + 'intValue': 10, + 'stringValue': 'my string', + 'nullValue': null, + 'nullValue2': null + }; + + assert.deepEqual(entityResult, entity); + + done(); + }); });