Skip to content

Commit

Permalink
Ensure returned versionId is a string when listing objects
Browse files Browse the repository at this point in the history
Returned versionId is a string when calling statObject(), as it is read
without transformation (casting) from the headers.

However, the xml parser casts automatically what looks like a number in
the responses. Consequentially, when the S3 storage provider returns a
VersionId with only numbers, listObjects() returns an object with a
versionId as a number, which is inconsistent with what returns other
methods like statObjects() and may result in erratic behaviors for the
program using these methods.
  • Loading branch information
fflorent committed Jul 20, 2023
1 parent 29665bd commit e01ed9d
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/xml-parsers.js
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@ const formatObjInfo = (content, opts = {}) => {
lastModified,
etag,
size: Size,
versionId: VersionId,
versionId: String(VersionId),
isLatest: IsLatest,
isDeleteMarker: opts.IsDeleteMarker ? opts.IsDeleteMarker : false,
}
Expand Down
41 changes: 41 additions & 0 deletions tests/unit/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import {
partsRequired,
} from '../../src/internal/helper.ts'
import * as Minio from '../../src/minio.js'
import { parseListObjects } from '../../src/xml-parsers.ts'

const Package = { version: 'development' }

Expand Down Expand Up @@ -2078,3 +2079,43 @@ describe('IP Address Validations', () => {
})
})
})

describe('xml-parser', function () {
describe('#listObjects()', function () {
it('should parse VersionId as string even if number is provided', function () {
const xml = `
<?xml version="1.0" encoding="UTF-8"?>
<ListVersionsResult xmlns="http://s3.amazonaws.com/doc/2006-03-01/">
<Name>some-bucket</Name>
<Prefix/>
<Delimiter>/</Delimiter>
<MaxKeys>1000</MaxKeys>
<IsTruncated>false</IsTruncated>
<EncodingType>url</EncodingType>
<KeyMarker/>
<VersionIdMarker/>
<Version>
<IsLatest>true</IsLatest>
<VersionId>1234</VersionId>
<ETag>"767dedcb515a0e2d995ed95191b75484-29"</ETag>
<Key>file.ext</Key>
<LastModified>2023-07-12T14:41:46.000Z</LastModified>
<Size>151306240</Size>
</Version>
<DeleteMarker>
<IsLatest>false</IsLatest>
<Key>file.ext</Key>
<LastModified>2023-07-12T14:39:22.000Z</LastModified>
<VersionId>5678</VersionId>
</DeleteMarker>
</ListVersionsResult>
`
const { objects } = parseListObjects(xml)

assert.equal(typeof objects[0].versionId, 'string')
assert.equal(objects[0].versionId, '1234')
assert.equal(typeof objects[1].versionId, 'string')
assert.equal(objects[1].versionId, '5678')
})
})
})

0 comments on commit e01ed9d

Please sign in to comment.