Skip to content

Commit

Permalink
Refresh error due to double encoding in verticalUrl (#836)
Browse files Browse the repository at this point in the history
* Fix error after refresh due to double encoding in verticalUrl

- URLSearchParams set() encoded verticalUrl even though it's already encoded since it's extracted from window's URL pathname. updated to append to the param string
- replace() only update the first instance unless a global modifier is used (e.g. this would cause refresh issue on mulilang site for verticalUrl as 'es/help_articles'. updated to replaceAll

J=SLAP-1376
TEST=manual

Launched multilang site with iframe data-path directed to a page with spaces in its names. Confirmed refresh and back/forward nav works accordingly.

Co-authored-by: Yen Truong <ytruong@yext.com>
  • Loading branch information
yen-tt and Yen Truong authored Jun 17, 2021
1 parent 9f92500 commit 72ba4c7
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
11 changes: 5 additions & 6 deletions layouts/html.hbs
Original file line number Diff line number Diff line change
Expand Up @@ -115,12 +115,11 @@
<script>
{{#babel}}
function iframeGetSearchParams() {
let params = new URLSearchParams(window.location.search);
let verticalUrl = window.location.pathname.substr(1)
if (verticalUrl) {
params.set('verticalUrl', verticalUrl);
}
return params.toString();
const params = window.location.search.substr(1);
const verticalUrl = window.location.pathname.substr(1);
return verticalUrl
? params + '&verticalUrl=' + verticalUrl
: params;
}
let iframeLoadedResolve;
window.iframeLoaded = new Promise(resolve => {
Expand Down
3 changes: 0 additions & 3 deletions static/js/iframe-common.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,6 @@ export function generateIFrame(domain, queryParam, urlParam) {
var paramString = window.location.search;
paramString = paramString.substr(1, paramString.length);

// Decode ASCII forward slash to avod repeat encodings on page refreshes
paramString = paramString.replace("%2F", "/");

// Parse the params out of the URL
var params = paramString.split('&'),
verticalUrl;
Expand Down

0 comments on commit 72ba4c7

Please sign in to comment.