Skip to content
This repository was archived by the owner on Mar 3, 2021. It is now read-only.

Commit eb76cbb

Browse files
committed
string with comma handled
1 parent 3071952 commit eb76cbb

File tree

3 files changed

+32
-5
lines changed

3 files changed

+32
-5
lines changed

remix-lib/src/execution/txFormat.js

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -169,7 +169,7 @@ module.exports = {
169169
* @param {Function} callbackDeployLibrary - callbackDeployLibrary
170170
*/
171171
buildData: function (contractName, contract, contracts, isConstructor, funAbi, params, callback, callbackStep, callbackDeployLibrary) {
172-
var funArgs = ''
172+
var funArgs = []
173173
var data = ''
174174
var dataHex = ''
175175

@@ -179,9 +179,32 @@ module.exports = {
179179
data = Buffer.from(dataHex, 'hex')
180180
} else {
181181
try {
182-
params = params.replace(/(^|,\s+|,)(\d+)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted number by quoted number
183-
params = params.replace(/(^|,\s+|,)(0[xX][0-9a-fA-F]+)(\s+,|,|$)/g, '$1"$2"$3') // replace non quoted hex string by quoted hex string
184-
funArgs = JSON.parse('[' + params + ']')
182+
if (params.length > 0) {
183+
params = params.split(',')
184+
for (let i = 0; i < params.length; i++) {
185+
let param = params[i].trim()
186+
if (param.charAt(0) === '"') {
187+
if (param.charAt(param.length - 1) === '"') {
188+
funArgs.push(param.slice(1, param.length - 1))
189+
} else {
190+
let lastIndex = false
191+
let paramStr = param.slice(1, param.length)
192+
for (let j = i + 1; !lastIndex; j++) {
193+
if (params[j].charAt(params[j].length - 1) === '"') {
194+
paramStr += ',' + params[j].slice(0, params[j].length - 1)
195+
i = j
196+
funArgs.push(paramStr)
197+
lastIndex = true
198+
} else {
199+
paramStr += ',' + params[j]
200+
}
201+
}
202+
}
203+
} else {
204+
funArgs.push(param)
205+
}
206+
}
207+
}
185208
} catch (e) {
186209
callback('Error encoding arguments: ' + e)
187210
return

remix-lib/test/txFormat.js

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,8 +35,12 @@ tape('ContractParameters - (TxFormat.buildData) - format input parameters', func
3535
})
3636

3737
function testWithInput (st, params, expected) {
38+
console.log('params-----', params)
3839
txFormat.buildData('uintContractTest', context.contract, context.output.contracts, true, context.contract.abi[0], params, (error, data) => {
39-
if (error) { return st.fails(error) }
40+
if (error) {
41+
console.log('------', error)
42+
return st.fails(error)
43+
}
4044
console.log(data)
4145
if (!data.dataHex.endsWith(expected)) {
4246
st.fail(`result of buildData ${data.dataHex} should end with ${expected} . `)
File renamed without changes.

0 commit comments

Comments
 (0)