Skip to content

Commit

Permalink
Handle invalid UTF8 hex
Browse files Browse the repository at this point in the history
* Handle invalid UTF8 hex strings for the `string` param type (return them as-is)
* Fix an eslint issue
* Fix a flow issue
  • Loading branch information
JamesLefrere committed Nov 30, 2018
1 parent a04d1ef commit 34e2f4a
Show file tree
Hide file tree
Showing 6 changed files with 16 additions and 3 deletions.
1 change: 1 addition & 0 deletions .flowconfig
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
[ignore]
<PROJECT_ROOT>/packages/colonyDapp/.*
<PROJECT_ROOT>/node_modules/oboe/test/json/incomplete.json

[include]

Expand Down
4 changes: 4 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,10 @@
* `setRecoveryRole`
* `setStorageSlotRecovery`

**Bug fixes**

* Improved handling of invalid UTF8 hex strings

## v1.7.5

**Bug fixes**
Expand Down
2 changes: 1 addition & 1 deletion docs/_API_ColonyClient.md
Original file line number Diff line number Diff line change
Expand Up @@ -470,7 +470,7 @@ An instance of a `ContractResponse`

### `setRewardInverse.send({ rewardInverse }, options)`

Set new colony recovery role. Can only be called by the founder role.
Set the reward inverse to pay out from revenue. e.g. if the fee is 1% (or 0.01), set 100

**Arguments**

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -148,6 +148,8 @@ describe('Parameter types', () => {
expect(convertOutputValue('a', 'string')).toBe('a');
expect(convertOutputValue('0x434f4c4e59', 'string')).toBe('COLNY');
expect(convertOutputValue('0x00', 'string')).toBe(null);
const invalidUtf8 = '0x712387612873682176387216312';
expect(convertOutputValue(invalidUtf8, 'string')).toBe(invalidUtf8);

// empty strings are cleaned:
expect(convertOutputValue('', 'string')).toBe(null);
Expand Down
7 changes: 6 additions & 1 deletion packages/colony-js-contract-client/src/modules/paramTypes.js
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,12 @@ const PARAM_TYPE_MAP: {
},
convertOutput(value: any) {
if (isHexStrict(value)) {
return isEmptyHexString(value) ? null : hexToUtf8(value);
if (isEmptyHexString(value)) return null;
try {
return hexToUtf8(value);
} catch (error) {
// ignore error: not a UTF8-encoded value
}
}
return typeof value === 'string' && value.length ? value : null;
},
Expand Down
3 changes: 2 additions & 1 deletion packages/colony-js-contract-loader/src/ContractLoader.js
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ export default class ContractLoader {
);
this._transform = transform;
}
// eslint-disable-next-line class-methods-use-this
/* eslint-disable class-methods-use-this,no-unused-vars */
async _load(
query: Query,
requiredProps?: RequiredContractProps, // eslint-disable-line no-unused-vars
Expand All @@ -83,6 +83,7 @@ export default class ContractLoader {
'ContractLoader._load() is expected to be defined in a derived class',
);
}
/* eslint-enable class-methods-use-this,no-unused-vars */
async load(
query: Query,
requiredProps?: RequiredContractProps = DEFAULT_REQUIRED_CONTRACT_PROPS,
Expand Down

0 comments on commit 34e2f4a

Please sign in to comment.