Skip to content

Commit

Permalink
Replaced substring from 0 index with startsWith (ethers-io#3691).
Browse files Browse the repository at this point in the history
  • Loading branch information
ricmoo authored and Woodpile37 committed Jan 14, 2024
1 parent 92abbcc commit fce4e4b
Show file tree
Hide file tree
Showing 8 changed files with 9 additions and 9 deletions.
2 changes: 1 addition & 1 deletion src.ts/abi/fragments.ts
Original file line number Diff line number Diff line change
Expand Up @@ -865,7 +865,7 @@ export class ParamType {
return new ParamType(_guard, name || "", type, "array", indexed, null, arrayLength, arrayChildren);
}

if (type === "tuple" || type.substring(0, 5) === "tuple(" || type[0] === "(") {
if (type === "tuple" || type.startsWith("tuple("/* fix: ) */) || type.startsWith("(" /* fix: ) */)) {
const comps = (obj.components != null) ? obj.components.map((c: any) => ParamType.from(c)): null;
const tuple = new ParamType(_guard, name || "", type, "tuple", indexed, comps, null, null);
// @TODO: use lexer to validate and normalize type
Expand Down
2 changes: 1 addition & 1 deletion src.ts/abi/typed.ts
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ export class Typed {
}

isData(): this is TypedData {
return (this.type.substring(0, 5) === "bytes");
return this.type.startsWith("bytes");
}

isString(): this is TypedString {
Expand Down
2 changes: 1 addition & 1 deletion src.ts/address/address.ts
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ export function getAddress(address: string): string {
if (address.match(/^(0x)?[0-9a-fA-F]{40}$/)) {

// Missing the 0x prefix
if (address.substring(0, 2) !== "0x") { address = "0x" + address; }
if (!address.startsWith("0x")) { address = "0x" + address; }

const result = getChecksumAddress(address);

Expand Down
2 changes: 1 addition & 1 deletion src.ts/contract/factory.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class ContractFactory<A extends Array<any> = Array<any>, I = BaseContract
bytecode = hexlify(getBytes(bytecode));
} else {
if (typeof(bytecode) === "object") { bytecode = bytecode.object; }
if (bytecode.substring(0, 2) !== "0x") { bytecode = "0x" + bytecode; }
if (!bytecode.startsWith("0x")) { bytecode = "0x" + bytecode; }
bytecode = hexlify(getBytes(bytecode));
}

Expand Down
2 changes: 1 addition & 1 deletion src.ts/utils/data.ts
Original file line number Diff line number Diff line change
Expand Up @@ -147,7 +147,7 @@ export function dataSlice(data: BytesLike, start?: number, end?: number): string
*/
export function stripZerosLeft(data: BytesLike): string {
let bytes = hexlify(data).substring(2);
while (bytes.substring(0, 2) == "00") { bytes = bytes.substring(2); }
while (bytes.startsWith("00")) { bytes = bytes.substring(2); }
return "0x" + bytes;
}

Expand Down
2 changes: 1 addition & 1 deletion src.ts/utils/maths.ts
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ export function toBeArray(_value: BigNumberish): Uint8Array {
*/
export function toQuantity(value: BytesLike | BigNumberish): string {
let result = hexlify(isBytesLike(value) ? value: toBeArray(value)).substring(2);
while (result.substring(0, 1) === "0") { result = result.substring(1); }
while (result.startsWith("0")) { result = result.substring(1); }
if (result === "") { result = "0"; }
return "0x" + result;
}
2 changes: 1 addition & 1 deletion src.ts/wallet/json-keystore.ts
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ function getAccount(data: any, _key: string): KeystoreAccount {
const address = computeAddress(privateKey);
if (data.address) {
let check = data.address.toLowerCase();
if (check.substring(0, 2) !== "0x") { check = "0x" + check; }
if (!check.startsWith("0x")) { check = "0x" + check; }

assertArgument(getAddress(check) === address, "keystore address/privateKey mismatch", "address", data.address);
}
Expand Down
4 changes: 2 additions & 2 deletions src.ts/wallet/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@ import {
} from "../utils/index.js";

export function looseArrayify(hexString: string): Uint8Array {
if (typeof(hexString) === 'string' && hexString.substring(0, 2) !== '0x') {
hexString = '0x' + hexString;
if (typeof(hexString) === "string" && !hexString.startsWith("0x")) {
hexString = "0x" + hexString;
}
return getBytesCopy(hexString);
}
Expand Down

0 comments on commit fce4e4b

Please sign in to comment.