diff --git a/packages/libs/web-common/src/controllers/SiteSearchController.tsx b/packages/libs/web-common/src/controllers/SiteSearchController.tsx index 2038fb0c33..dd6aa89693 100644 --- a/packages/libs/web-common/src/controllers/SiteSearchController.tsx +++ b/packages/libs/web-common/src/controllers/SiteSearchController.tsx @@ -45,7 +45,27 @@ interface Props { hasUserSetPreferredOrganisms?: boolean; } -export default function SiteSearchController({ +const smartQuoteRegex = /\u{201c}|\u{201d}/gu; + +// This is a wrapper for the real SiteSearchController component. +// It will check the search input for smart quotes and replace them +// with ascii quotes. +export default function SiteSearchControllerWrapper(props: Props) { + const [params, updateParams] = useQueryParams(SEARCH_TERM_PARAM); + const searchString = Array.isArray(params.q) ? params.q[0] : params.q || ''; + const shouldRedirect = smartQuoteRegex.test(searchString); + useEffect(() => { + if (shouldRedirect) { + updateParams({ + [SEARCH_TERM_PARAM]: searchString.replace(smartQuoteRegex, '"'), + }); + } + }, [updateParams, shouldRedirect]); + + return shouldRedirect ? null : ; +} + +function SiteSearchController({ offerOrganismFilter = true, preferredOrganisms, preferredOrganismsEnabled,