Skip to content

Commit

Permalink
🐛 Fix decoding bug for the "0x" string
Browse files Browse the repository at this point in the history
  • Loading branch information
nazarhussain committed Jan 25, 2022
1 parent 5df6818 commit d2fec98
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 1 deletion.
4 changes: 3 additions & 1 deletion packages/web3-eth-abi/src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,9 @@ ABICoder.prototype.decodeParametersWith = function (outputs, bytes, loose) {

outputs.forEach(function (output, i) {
var decodedValue = res[returnValue.__length__];
decodedValue = (decodedValue === '0x') ? null : decodedValue;

// only convert `0x` to null if it's not string value
decodedValue = (decodedValue === '0x' && output.type !== 'string') ? null : decodedValue;

returnValue[i] = decodedValue;

Expand Down
5 changes: 5 additions & 0 deletions packages/web3-eth-abi/types/tests/abi-coder-test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,11 @@ abiCoder.decodeParameter(
00000000000038000000000000000000000000000000000000000000000000000000000000002d00000000000000000000000000000000000000
0000000000000000000000004e`
);
// $ExpectType string
abiCoder.decodeParameter(
'string',
'0x000000000000000000000000000000000000000000000000000000000000002000000000000000000000000000000000000000000000000000000000000000023078000000000000000000000000000000000000000000000000000000000000'
);

// $ExpectError
abiCoder.decodeParameter('uint256', [345]);
Expand Down

0 comments on commit d2fec98

Please sign in to comment.