Skip to content

Commit

Permalink
force xml parser to treat bucket name as string (#1343)
Browse files Browse the repository at this point in the history
  • Loading branch information
prakashsvmx authored Sep 4, 2024
1 parent fe4d95f commit 147072e
Showing 1 changed file with 22 additions and 3 deletions.
25 changes: 22 additions & 3 deletions src/internal/xml-parser.ts
Original file line number Diff line number Diff line change
Expand Up @@ -213,23 +213,42 @@ export function parseListParts(xml: string): {
return result
}

export function parseListBucket(xml: string) {
export function parseListBucket(xml: string): BucketItemFromList[] {
let result: BucketItemFromList[] = []
const parsedXmlRes = parseXml(xml)
const listBucketResultParser = new XMLParser({
parseTagValue: true, // Enable parsing of values
numberParseOptions: {
leadingZeros: false, // Disable number parsing for values with leading zeros
hex: false, // Disable hex number parsing - Invalid bucket name
skipLike: /^[0-9]+$/, // Skip number parsing if the value consists entirely of digits
},
tagValueProcessor: (tagName, tagValue = '') => {
// Ensure that the Name tag is always treated as a string
if (tagName === 'Name') {
return tagValue.toString()
}
return tagValue
},
ignoreAttributes: false, // Ensure that all attributes are parsed
})

const parsedXmlRes = listBucketResultParser.parse(xml)

if (!parsedXmlRes.ListAllMyBucketsResult) {
throw new errors.InvalidXMLError('Missing tag: "ListAllMyBucketsResult"')
}

const { ListAllMyBucketsResult: { Buckets = {} } = {} } = parsedXmlRes

if (Buckets.Bucket) {
result = toArray(Buckets.Bucket).map((bucket = {}) => {
const { Name: bucketName, CreationDate } = bucket
const creationDate = new Date(CreationDate)

return { name: bucketName, creationDate: creationDate }
return { name: bucketName, creationDate }
})
}

return result
}

Expand Down

0 comments on commit 147072e

Please sign in to comment.