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

Correctly decode UTF-8 #2129

Merged
merged 1 commit into from Jun 25, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 10 additions & 1 deletion packages/truffle-decoder/lib/decode/value.ts
Expand Up @@ -4,6 +4,7 @@ const debug = debugModule("decoder:decode:value");
import read from "../read";
import * as DecodeUtils from "truffle-decode-utils";
import BN from "bn.js";
import utf8 from "utf8";
import { DataPointer } from "../types/pointer";
import { EvmInfo } from "../types/evm";
import { EvmEnum } from "../interface/contract-decoder";
Expand Down Expand Up @@ -60,7 +61,15 @@ export default function* decodeValue(definition: DecodeUtils.AstDefinition, poin
if (typeof bytes == "string") {
return bytes;
}
return String.fromCharCode.apply(undefined, bytes);
try {
return utf8.decode(String.fromCharCode.apply(undefined, bytes));
}
catch(error) {
return null; //HACK: we use null as our error value here rather than
//undefined to prevent potentially throwing the debugger into an
//infinite loop
//(this will be saner in 5.1 :P )
}

case "enum":
const numRepresentation = DecodeUtils.Conversion.toBN(bytes).toNumber();
Expand Down
2 changes: 2 additions & 0 deletions packages/truffle-decoder/package.json
Expand Up @@ -33,6 +33,7 @@
"@types/lodash.clonedeep": "^4.5.4",
"@types/lodash.isequal": "^4.5.4",
"@types/lodash.merge": "^4.6.4",
"@types/utf8": "^2.1.6",
"@types/web3": "^1.0.5",
"json-schema-to-typescript": "^5.5.0",
"truffle-contract-schema": "^3.0.11",
Expand All @@ -47,6 +48,7 @@
"lodash.isequal": "^4.5.0",
"lodash.merge": "^4.6.1",
"truffle-decode-utils": "^1.0.14",
"utf8": "^3.0.0",
"web3": "1.0.0-beta.37"
},
"peerDependencies": {
Expand Down
5 changes: 5 additions & 0 deletions yarn.lock
Expand Up @@ -1069,6 +1069,11 @@
resolved "https://registry.yarnpkg.com/@types/underscore/-/underscore-1.8.18.tgz#025371cfe062439aaa088d2b64af87cbcfe3c2b7"
integrity sha512-mXQ8u416FWMPjp2zWrcVmOZtzKQM6IeyVcuE+RGF/04JLBrMjfnmNKn74VN8fIkFzU97TpzkP0ny0p0h65eC7w==

"@types/utf8@^2.1.6":
version "2.1.6"
resolved "https://registry.yarnpkg.com/@types/utf8/-/utf8-2.1.6.tgz#430cabb71a42d0a3613cce5621324fe4f5a25753"
integrity sha512-pRs2gYF5yoKYrgSaira0DJqVg2tFuF+Qjp838xS7K+mJyY2jJzjsrl6y17GbIa4uMRogMbxs+ghNCvKg6XyNrA==

"@types/web3@^1.0.18", "@types/web3@^1.0.5":
version "1.0.18"
resolved "https://registry.yarnpkg.com/@types/web3/-/web3-1.0.18.tgz#87a8651041d21fc37602ff02327df2c7ecf105d1"
Expand Down