From fee9dc09cfff9ed510f22cbc9ca727e729ef379b Mon Sep 17 00:00:00 2001 From: jonathanlei Date: Mon, 26 Jun 2023 14:56:05 -0700 Subject: [PATCH 1/2] strip leading and trailing quotes from search --- src/containers/Header/Search.tsx | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/src/containers/Header/Search.tsx b/src/containers/Header/Search.tsx index 3a77957ad..424c53604 100644 --- a/src/containers/Header/Search.tsx +++ b/src/containers/Header/Search.tsx @@ -104,15 +104,17 @@ export const Search = ({ callback = () => {} }: SearchProps) => { const history = useHistory() const handleSearch = async (id: string) => { - const type = await getIdType(id, socket) - + const strippedId = id.replace(/^["']|["']$/g, '') + const type = await getIdType(strippedId, socket) track('search', { - search_term: id, + search_term: strippedId, search_category: type, }) history.push( - type === 'invalid' ? `/search/${id}` : `/${type}/${normalize(id, type)}`, + type === 'invalid' + ? `/search/${strippedId}` + : `/${type}/${normalize(strippedId, type)}`, ) callback() } From 2fb98c59107b66f4ef6f216dc06c014f12de3fdd Mon Sep 17 00:00:00 2001 From: jonathanlei Date: Mon, 26 Jun 2023 15:50:47 -0700 Subject: [PATCH 2/2] add tests --- src/containers/Header/test/Search.test.js | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/src/containers/Header/test/Search.test.js b/src/containers/Header/test/Search.test.js index 7dd607187..d458373c7 100644 --- a/src/containers/Header/test/Search.test.js +++ b/src/containers/Header/test/Search.test.js @@ -47,6 +47,9 @@ describe('Search component', () => { const paystring = 'blunden$paystring.crypto.com' const paystringWithAt = 'blunden@paystring.crypto.com' const validator = 'nHUFE9prPXPrHcG3SkwP1UzAQbSphqyQkQK9ATXLZsfkezhhda3p' + const addressWithQuotes = '"rGFuMiw48HdbnrUbkRYuitXTmfrDBNTCnX"' + const addressWithSpace = ' rGFuMiw48HdbnrUbkRYuitXTmfrDBNTCnX ' + const addressWithSingleQuote = '"rGFuMiw48HdbnrUbkRYuitXTmfrDBNTCnX' const hash = '59239EA78084F6E2F288473F8AE02F3E6FC92F44BDE59668B5CAE361D3D32838' @@ -73,6 +76,21 @@ describe('Search component', () => { await flushPromises() expect(window.location.pathname).toEqual(`/accounts/${rippleAddress}`) + input.instance().value = addressWithQuotes + input.simulate('keyDown', { key: 'Enter' }) + await flushPromises() + expect(window.location.pathname).toEqual(`/accounts/${rippleAddress}`) + + input.instance().value = addressWithSingleQuote + input.simulate('keyDown', { key: 'Enter' }) + await flushPromises() + expect(window.location.pathname).toEqual(`/accounts/${rippleAddress}`) + + input.instance().value = addressWithSpace + input.simulate('keyDown', { key: 'Enter' }) + await flushPromises() + expect(window.location.pathname).toEqual(`/accounts/${rippleAddress}`) + input.instance().value = rippleXAddress input.simulate('keyDown', { key: 'Enter' }) await flushPromises()