From d24810e3682ea154fb2ea45865e1f38c8c76e54c Mon Sep 17 00:00:00 2001 From: Brian Hoffman Date: Fri, 18 Sep 2020 07:10:21 -0400 Subject: [PATCH 1/2] Do not strip 0x in the middle of the string This is causing checksum validation issues for addresses where 0x appears in the middle of the address not just at the beginning. --- util/utils.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/util/utils.go b/util/utils.go index 32a0e64430..7b98efff1f 100644 --- a/util/utils.go +++ b/util/utils.go @@ -65,7 +65,10 @@ const EmojiPattern = "[\\x{2712}\\x{2714}\\x{2716}\\x{271d}\\x{2721}\\x{2728}\\x // NormalizeAddress is used to strip the 0x prefix func NormalizeAddress(addr string) string { - return strings.Replace(addr, "0x", "", 1) + if addr[0:2] == "0x" { + return strings.Replace(addr, "0x", "", 1) + } + return addr } // AreAddressesEqual - check if addresses are equal after normalizing them From 94b3c59bb6a4e9081b22dcc0e2e414e81ccccd99 Mon Sep 17 00:00:00 2001 From: Brian Hoffman Date: Fri, 18 Sep 2020 11:44:19 -0400 Subject: [PATCH 2/2] Refactor to use trimprefix --- util/utils.go | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/util/utils.go b/util/utils.go index 7b98efff1f..cde76f84e6 100644 --- a/util/utils.go +++ b/util/utils.go @@ -65,10 +65,7 @@ const EmojiPattern = "[\\x{2712}\\x{2714}\\x{2716}\\x{271d}\\x{2721}\\x{2728}\\x // NormalizeAddress is used to strip the 0x prefix func NormalizeAddress(addr string) string { - if addr[0:2] == "0x" { - return strings.Replace(addr, "0x", "", 1) - } - return addr + return strings.TrimPrefix(addr, "0x") } // AreAddressesEqual - check if addresses are equal after normalizing them