Skip to content

Commit

Permalink
strip leading and trailing quotes from search (#759)
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanlei authored Jun 26, 2023
1 parent 3182eba commit 99f00d1
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 4 deletions.
10 changes: 6 additions & 4 deletions src/containers/Header/Search.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -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()
}
Expand Down
18 changes: 18 additions & 0 deletions src/containers/Header/test/Search.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ describe('Search component', () => {
const paystring = 'blunden$paystring.crypto.com'
const paystringWithAt = '[email protected]'
const validator = 'nHUFE9prPXPrHcG3SkwP1UzAQbSphqyQkQK9ATXLZsfkezhhda3p'
const addressWithQuotes = '"rGFuMiw48HdbnrUbkRYuitXTmfrDBNTCnX"'
const addressWithSpace = ' rGFuMiw48HdbnrUbkRYuitXTmfrDBNTCnX '
const addressWithSingleQuote = '"rGFuMiw48HdbnrUbkRYuitXTmfrDBNTCnX'

const hash =
'59239EA78084F6E2F288473F8AE02F3E6FC92F44BDE59668B5CAE361D3D32838'
Expand All @@ -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()
Expand Down

0 comments on commit 99f00d1

Please sign in to comment.