Skip to content

Commit

Permalink
Remove special characters from search
Browse files Browse the repository at this point in the history
  • Loading branch information
klzns committed Dec 7, 2020
1 parent b14fc6f commit 960844a
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 29 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@ The format is based on [Keep a Changelog](http://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](http://semver.org/spec/v2.0.0.html).

## [Unreleased]
### Fixed
- Remove special characters from search.

## [2.136.6] - 2020-12-03

Expand Down
39 changes: 10 additions & 29 deletions node/clients/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,30 +56,11 @@ export class Catalog extends AppClient {
: '/proxy/catalog'
}

private searchEncodeURI = (str: string) => {
const result = str.replace(/[%"'.()]/g, (c: string) => {
switch (c) {
case '%':
return "@perc@"
case '"':
return "@quo@"
case '\'':
return "@squo@"
case '.':
return "@dot@"
case '(':
return "@lpar@"
case ')':
return "@rpar@"
default: {
return c
}
}
})
return result
private removeSpecialCharacters = (str: string) => {
return str.replace(/[%"'.()+]/g, '')
}

public pageType = (path: string, query: string = '') => {
public pageType = (path: string, query = '') => {
const pageTypePath = path.startsWith('/') ? path.substr(1) : path

const pageTypeQuery = !query || query.startsWith('?') ? query : `?${query}`
Expand Down Expand Up @@ -186,7 +167,9 @@ export class Catalog extends AppClient {

return this.get(
`/pub/facets/search/${encodeURI(
`${this.searchEncodeURI(encodeURIComponent(path.trim()))}${options ? '?' + options : ''}`
`${this.removeSpecialCharacters(path.trim())}${
options ? `?${options}` : ''
}`
)}`,
{ metric: 'catalog-facets' }
)
Expand Down Expand Up @@ -255,12 +238,10 @@ export class Catalog extends AppClient {
map = '',
hideUnavailableItems = false,
}: SearchArgs) => {
// const sanitizedQuery = encodeURIComponent(
// decodeURIComponent(query || '').trim()
// )
const sanitizedQuery = this.searchEncodeURI(encodeURIComponent(
this.searchEncodeURI(decodeURIComponent(query || '').trim())
))
const sanitizedQuery = encodeURIComponent(
this.removeSpecialCharacters(decodeURIComponent(query || '').trim())
)

if (hideUnavailableItems) {
const segmentData = (this.context as CustomIOContext).segment

Expand Down

0 comments on commit 960844a

Please sign in to comment.