Skip to content

Commit

Permalink
build clean query string
Browse files Browse the repository at this point in the history
  • Loading branch information
bblaisATcoveo committed Jul 12, 2024
1 parent f07886f commit 6629be6
Showing 1 changed file with 19 additions and 4 deletions.
23 changes: 19 additions & 4 deletions src/connector.js
Original file line number Diff line number Diff line change
Expand Up @@ -619,12 +619,11 @@ function initEngine() {

// Get the query portion of the URL
const fragment = () => {
const hash = window.location.hash.slice( 1 );
if (!statusController.state.firstSearchExecuted && !hashParams.q ) {
return window.location.search.slice( 1 ).replaceAll( '+', ' ' ); // use query string if hash is empty
if ( !statusController.state.firstSearchExecuted && !hashParams.q ) {
return buildCleanQueryString( urlParams );
}

return hash;
return buildCleanQueryString( hashParams );
};

urlManager = buildUrlManager( headlessEngine, {
Expand Down Expand Up @@ -763,6 +762,22 @@ function updateSearchBoxState( newState ) {
}
}

// rebuild a clean query string out of a JSON object
function buildCleanQueryString( paramsObject ) {
let urlParam = "";
for ( var prop in paramsObject ) {
if ( paramsObject[ prop ] ) {
if ( urlParam !== "" ) {
urlParam += "&";
}

urlParam += prop + "=" + DOMPurify.sanitize( paramsObject[ prop ].replaceAll( '+', ' ' ) );
}
}

return urlParam;
}

// Filters out dangerous URIs that can create XSS attacks such as `javascript:`.
function filterProtocol( uri ) {

Expand Down

0 comments on commit 6629be6

Please sign in to comment.