Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixed: hex parsed as number #1133

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions src/main/helpers.js
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,12 @@ import stream from 'stream'
import mime from 'mime-types'
var Crypto = require('crypto-browserify')
const { XMLParser } = require("fast-xml-parser")
const fxp = new XMLParser()
const fxp = new XMLParser({
numberParseOptions: {
leadingZeros: false,
hex: false,
}
})

const ipaddr = require('ipaddr.js')
import { isBrowser } from "browser-or-node"
Expand Down Expand Up @@ -379,7 +384,7 @@ export function getSourceVersionId(headers={}){
export function sanitizeETag(etag='') {
var replaceChars = {'"':'','"':'','"':'','"':'','&#x00022':''}
return etag.replace(/^("|"|")|("|"|")$/g, m => replaceChars[m])

}

export const RETENTION_MODES ={
Expand Down
29 changes: 20 additions & 9 deletions src/test/unit/test.js
Original file line number Diff line number Diff line change
Expand Up @@ -20,17 +20,21 @@ import { assert } from 'chai'
import Nock from 'nock'
import Stream from 'stream'
import * as Minio from '../../../dist/main/minio'
import { isValidEndpoint,
import { isValidEndpoint,
isValidIP, makeDateLong,
makeDateShort,partsRequired,
CopySourceOptions,
CopyDestinationOptions,
isArray,
calculateEvenSplits,
parseXml,
} from '../../../dist/main/helpers'

var Package = require('../../../package.json')

const { XMLParser } = require("fast-xml-parser")
const fxp = new XMLParser()

describe('Helpers', () => {
it('should validate for s3 endpoint', () => {
assert.equal(isValidEndpoint('s3.amazonaws.com'), true)
Expand All @@ -44,7 +48,7 @@ describe('Helpers', () => {
it('should fail for invalid endpoint characters', () => {
assert.equal(isValidEndpoint('111.#2.11'), false)
})

it('should make date short', () => {
let date = new Date('2012-12-03T17:25:36.331Z')

Expand All @@ -56,6 +60,13 @@ describe('Helpers', () => {
assert.equal(makeDateLong(date), '20170811T172634Z')
})

it('should object key equal 0xf2', () => {
let xml = '<Key xmlns="http://s3.amazonaws.com/doc/2006-03-01/">0xf2</Key>'
let xmlobj = parseXml(xml)
let originxmlobj = fxp.parse(xml)
assert.equal(xmlobj.Key, '0xf2')
assert.equal(originxmlobj.Key, '242')
})

// Adopted from minio-go sdk
const oneGB =1024 * 1024 * 1024
Expand All @@ -72,7 +83,7 @@ describe('Helpers', () => {
const maxMultipartPutObjectSize = 1024 * 1024 * 1024 * 1024 * 5

it('Parts Required Test cases ', () =>{

const expectedPartsRequiredTestCases = [
{value:0, expected:0},
{value:1, expected:1},
Expand Down Expand Up @@ -157,9 +168,9 @@ describe('Helpers', () => {
assert.equal(endIndex, expectedSplitsTestCases.expectedEnd)
}
})

})

})

describe('CopyConditions', () => {
Expand Down Expand Up @@ -707,7 +718,7 @@ describe('Client', function() {
done()
}
})

})

describe('#removeObject(bucket, object, callback)', () => {
Expand Down Expand Up @@ -754,7 +765,7 @@ describe('Client', function() {
done()
}
})

it('should fail on empty (string) removeOpts', (done) => {
try {
client.removeObject('hello', 'testRemoveOpts','', function() {})
Expand Down Expand Up @@ -1594,7 +1605,7 @@ describe('Client', function() {
done()
}
})

})
})
describe('Select Object Content APIs', ()=> {
Expand Down Expand Up @@ -1644,7 +1655,7 @@ describe('IP Address Validations', ()=>{
it('should validate for valid ip', () => {
assert.equal(isValidIP('1.1.1.1'), true)
})

it('Check list of IPV4 Invalid addresses', () => {
const invalidIpv4 = [' 127.0.0.1', '127.0.0.1 ', '127.0.0.1 127.0.0.1', '127.0.0.256', '127.0.0.1//1', '127.0.0.1/0x1', '127.0.0.1/-1', '127.0.0.1/ab', '127.0.0.1/', '127.0.0.256/32', '127.0.0.1/33']
invalidIpv4.map(ip=>{
Expand Down