Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove special characters from Search #503

Merged
merged 2 commits into from
Dec 8, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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
10 changes: 8 additions & 2 deletions node/clients/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,10 @@ export class Catalog extends AppClient {
: '/proxy/catalog'
}

private removeSpecialCharacters = (str: string) => {
return str.replace(/[%"'.()+]/g, '')
}

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

Expand Down Expand Up @@ -163,7 +167,9 @@ export class Catalog extends AppClient {

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

if (hideUnavailableItems) {
Expand Down