diff --git a/src/main/xml-parsers.js b/src/main/xml-parsers.js index de96b01c5..8264402d6 100644 --- a/src/main/xml-parsers.js +++ b/src/main/xml-parsers.js @@ -34,8 +34,8 @@ var parseXml = (xml) => { export function parseError(xml, headerInfo) { var xmlErr = {} var xmlObj = fxp.parse(xml) - if (xmlObj['Error']) { - xmlErr = xmlObj['Error'] + if (xmlObj.Error) { + xmlErr = xmlObj.Error } var e = new errors.S3Error() @@ -76,7 +76,9 @@ export function parseListMultipart(xml) { prefixes: [], isTruncated: false } - var xmlobj = parseXml(xml) + + var xmlobj = parseXml(xml) + if (!xmlobj.ListMultipartUploadsResult) { throw new errors.InvalidXMLError('Missing tag: "ListMultipartUploadsResult"') } @@ -87,13 +89,20 @@ export function parseListMultipart(xml) { if (xmlobj.CommonPrefixes) xmlobj.CommonPrefixes.forEach(prefix => { result.prefixes.push({prefix: prefix[0]}) }) - if (xmlobj.Upload) (upload => { - result.uploads.push({ - key: upload.Key, - uploadId: upload.UploadId[0], - initiated: new Date(upload.Initiated[0]) + if (xmlobj.Upload) { + if (!Array.isArray(xmlobj.Upload)) { + xmlobj.Upload = Array(xmlobj.Upload) + } + xmlobj.Upload.forEach(upload => { + var key = upload.Key + var uploadId = upload.UploadId + var initiator = {id: upload.Initiator.ID, displayName: upload.Initiator.DisplayName} + var owner = {id: upload.Owner.ID, displayName: upload.Owner.DisplayName} + var storageClass = upload.StorageClass + var initiated = new Date(upload.Initiated) + result.uploads.push({key, uploadId, initiator, owner, storageClass, initiated}) }) - }) + } return result } @@ -105,11 +114,14 @@ export function parseListBucket(xml) { if (!xmlobj.ListAllMyBucketsResult) { throw new errors.InvalidXMLError('Missing tag: "ListAllMyBucketsResult"') } - var allMyBuckets = xmlobj.ListAllMyBucketsResult + xmlobj = xmlobj.ListAllMyBucketsResult - if (allMyBuckets.Buckets) { - if (allMyBuckets.Buckets.Bucket) { - allMyBuckets.Buckets.Bucket.forEach(bucket => { + if (xmlobj.Buckets) { + if (xmlobj.Buckets.Bucket) { + if (!Array.isArray(xmlobj.Buckets.Bucket)) { + xmlobj.Buckets.Bucket = Array(xmlobj.Buckets.Bucket) + } + xmlobj.Buckets.Bucket.forEach(bucket => { var name = bucket.Name var creationDate = new Date(bucket.CreationDate) result.push({name, creationDate}) @@ -261,7 +273,7 @@ export function parseListObjects(xml) { var lastModified = new Date(content.LastModified) var etag = content.ETag.replace(/^"/g, '').replace(/"$/g, '') .replace(/^"/g, '').replace(/"$/g, '') - .replace(/^"/g, '').replace(/^"$/g, '') + .replace(/^"/g, '').replace(/"$/g, '') var size = +content.Size result.objects.push({name, lastModified, etag, size}) nextMarker = name diff --git a/src/test/functional/functional-tests.js b/src/test/functional/functional-tests.js index fde02cd0d..f4fea7f58 100644 --- a/src/test/functional/functional-tests.js +++ b/src/test/functional/functional-tests.js @@ -1068,6 +1068,7 @@ describe('functional tests', function() { }) step(`listObjects(bucketName, prefix, recursive)_bucketName:${bucketName}, recursive:false_`, done => { + listArray = [] client.listObjects(bucketName, '', false) .on('error', done) .on('end', () => {