Skip to content

Commit

Permalink
Replace smart quotes with ascii quotes (#64)
Browse files Browse the repository at this point in the history
* Add a wrapper component that does a redirect, if smart quotes are found

* Replace smart quotes with ascii quotes
  • Loading branch information
dmfalke authored Apr 17, 2023
1 parent 78a6cbb commit dbb7236
Showing 1 changed file with 21 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 : <SiteSearchController {...props} />;
}

function SiteSearchController({
offerOrganismFilter = true,
preferredOrganisms,
preferredOrganismsEnabled,
Expand Down

0 comments on commit dbb7236

Please sign in to comment.