some housekeeping

This commit is contained in:
spencerwooo
2022-02-06 16:01:21 +08:00
parent d4998466de
commit 96b3c92df9
+11 -2
View File
@@ -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 encodes the '<' and '>' characters, replaces '?' and '/' characters with ' ', and replaces ''' with '''' accroading to https://stackoverflow.com/questions/41491222/single-quote-escaping-in-microsoft-graph.
* @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(/'/g, "''").replace('<', ' &lt; ').replace('>', ' &gt; ').replace('?', ' ').replace('/', ' ')
const sanitisedQuery = query
.replace(/'/g, "''")
.replace('<', ' &lt; ')
.replace('>', ' &gt; ')
.replace('?', ' ')
.replace('/', ' ')
return encodeURIComponent(sanitisedQuery)
}