Skip to content
This repository has been archived by the owner on Oct 30, 2024. It is now read-only.

parseSignature breaks on zero input params #35

Closed
kumavis opened this issue Nov 11, 2016 · 2 comments
Closed

parseSignature breaks on zero input params #35

kumavis opened this issue Nov 11, 2016 · 2 comments

Comments

@kumavis
Copy link
Member

kumavis commented Nov 11, 2016

src: https://github.com/ethereumjs/ethereumjs-abi/blob/master/lib/index.js#L81-L83

works

/^(\w+)\((.+)\)$/.exec('hi(bytes)')
["hi(bytes)", "hi", "bytes"]

breaks

/^(\w+)\((.+)\)$/.exec('hi()')
null
@kumavis
Copy link
Member Author

kumavis commented Nov 11, 2016

this seems to work, will PR

// someMethod()
// someMethod(bytes,uint)
// someMethod(bytes,uint):(boolean)
function parseSignature (sigString) {
  var methodEndIndex = sigString.indexOf('(')
  if (methodEndIndex === -1) {
    throw new Error('Invalid method signature')
  }
  var methodName = sigString.slice(0,methodEndIndex)
  var allArgs = sigString.slice(methodEndIndex+1,-1)
  var [ inputArgs, outputArgs ] = allArgs.split(':')

  return {
    method: methodName,
    args: (inputArgs ? inputArgs.split(',') : []),
    retargs: (outputArgs ? outputArgs.split(',') : null),
  }
}

@mcgwiz
Copy link

mcgwiz commented Nov 21, 2018

In order to handle "someMethod():(boolean)" you might consider changing

var [ inputArgs, outputArgs ] = allArgs.split(':')

to

var [ inputArgs, outputArgs ] = allArgs.split('):(')

# for free to subscribe to this conversation on GitHub. Already have an account? #.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants