Skip to content

Commit

Permalink
Attempt to fix the special character issue
Browse files Browse the repository at this point in the history
  • Loading branch information
iaron authored and klzns committed Nov 27, 2020
1 parent 74bb78a commit a1e03db
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 9 deletions.
34 changes: 30 additions & 4 deletions node/clients/catalog.ts
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,29 @@ export class Catalog extends AppClient {
this.basePath = ctx.sessionToken ? '/proxy/authenticated/catalog' : '/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
}

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

Expand Down Expand Up @@ -156,7 +179,7 @@ export class Catalog extends AppClient {
const [path, options] = decodeURI(facets).split('?')
return this.get(
`/pub/facets/search/${encodeURI(
`${path.trim()}${options ? '?' + options : ''}`
`${this.searchEncodeURI(encodeURIComponent(path.trim()))}${options ? '?' + options : ''}`
)}`,
{ metric: 'catalog-facets' }
)
Expand Down Expand Up @@ -222,9 +245,12 @@ export class Catalog extends AppClient {
map = '',
hideUnavailableItems = false,
}: SearchArgs) => {
const sanitizedQuery = encodeURIComponent(
decodeURIComponent(query || '').trim()
)
// const sanitizedQuery = encodeURIComponent(
// decodeURIComponent(query || '').trim()
// )
const sanitizedQuery = this.searchEncodeURI(encodeURIComponent(
this.searchEncodeURI(decodeURIComponent(query || '').trim())
))
if (hideUnavailableItems) {
const segmentData = (this.context as CustomIOContext).segment
salesChannel = (segmentData && segmentData.channel.toString()) || ''
Expand Down
2 changes: 1 addition & 1 deletion node/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
"querystring": "^0.2.0",
"ramda": "^0.26.1",
"slugify": "^1.2.6",
"typescript": "3.9.7",
"typescript": "3.8.3",
"unorm": "^1.5.0",
"url-parse": "^1.2.0"
},
Expand Down
8 changes: 4 additions & 4 deletions node/yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -6491,10 +6491,10 @@ typescript@3.0.3:
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.0.3.tgz#4853b3e275ecdaa27f78fda46dc273a7eb7fc1c8"
integrity sha512-kk80vLW9iGtjMnIv11qyxLqZm20UklzuR2tL0QAnDIygIUIemcZMxlMWudl9OOt76H3ntVzcTiddQ1/pAAJMYg==

typescript@3.9.7:
version "3.9.7"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.9.7.tgz#98d600a5ebdc38f40cb277522f12dc800e9e25fa"
integrity sha512-BLbiRkiBzAwsjut4x/dsibSTB6yWpwT5qWmC2OfuCg3GgVQCSgMs4vEctYPhsaGtd0AeuuHMkjZ2h2WG8MSzRw==
typescript@3.8.3:
version "3.8.3"
resolved "https://registry.yarnpkg.com/typescript/-/typescript-3.8.3.tgz#409eb8544ea0335711205869ec458ab109ee1061"
integrity sha512-MYlEfn5VrLNsgudQTVJeNaQFUAI7DkhnOjdpAp4T+ku1TfQClewlbSuTVHiA+8skNBgaf02TL/kLOvig4y3G8w==

typescript@^3.7.3:
version "3.7.3"
Expand Down

0 comments on commit a1e03db

Please sign in to comment.