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() } 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()