Merge pull request #354 from Ovler-Young/Try-to-fix-CJK-search
This commit is contained in:
commit
f7771e5174
|
|
@ -9,10 +9,19 @@ import siteConfig from '../../config/site.config'
|
|||
* Sanitize the search query
|
||||
*
|
||||
* @param query User search query, which may contain special characters
|
||||
* @returns Sanitised query string which replaces non-alphanumeric characters with ' '
|
||||
* @returns Sanitised query string, which:
|
||||
* - encodes the '<' and '>' characters,
|
||||
* - replaces '?' and '/' characters with ' ',
|
||||
* - replaces ''' with ''''
|
||||
* Reference: https://stackoverflow.com/questions/41491222/single-quote-escaping-in-microsoft-graph.
|
||||
*/
|
||||
function sanitiseQuery(query: string): string {
|
||||
const sanitisedQuery = query.replace(/[^a-zA-Z0-9]/g, ' ')
|
||||
const sanitisedQuery = query
|
||||
.replace(/'/g, "''")
|
||||
.replace('<', ' < ')
|
||||
.replace('>', ' > ')
|
||||
.replace('?', ' ')
|
||||
.replace('/', ' ')
|
||||
return encodeURIComponent(sanitisedQuery)
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue