Skip to content

Commit

Permalink
fix: improve relative URL handling (#134)
Browse files Browse the repository at this point in the history
  • Loading branch information
rentallect authored Nov 29, 2022
1 parent 1c94c6d commit 37f06ed
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 16 deletions.
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@
},
"dependencies": {
"@babel/runtime": "^7.17.9",
"@openziti/ziti-browzer-core": "^0.17.0",
"@openziti/ziti-browzer-core": "^0.17.1",
"cookie-interceptor": "^1.0.0",
"core-js": "^3.22.8",
"js-base64": "^3.7.2",
Expand All @@ -102,4 +102,4 @@
"uuid": "^8.3.2",
"workbox-window": "^6.5.3"
}
}
}
25 changes: 15 additions & 10 deletions src/runtime.js
Original file line number Diff line number Diff line change
Expand Up @@ -850,7 +850,7 @@ if (isUndefined(window.zitiBrowzerRuntime)) {
}

else if (event.data.type === 'SET_COOKIE') {
let cookie = event.data.payload.replace('HttpOnly','');
let cookie = event.data.payload.replace(/HttpOnly/gi,'');
zitiBrowzerRuntime.logger.info(`A COOKIE has arrived with val ${event.data.payload}`);
zitiBrowzerRuntime.logger.info(`document.cookie before: `, document.cookie);
document.cookie = cookie;
Expand Down Expand Up @@ -1019,8 +1019,6 @@ HotKey: '<strong>${window.zitiBrowzerRuntime.hotKey}</strong>'

}

window.zitiBrowzerRuntime.noActiveChannelDetectedEnabled = true;

})();

}
Expand Down Expand Up @@ -1056,6 +1054,8 @@ const zitiFetch = async ( url, opts ) => {

await window.zitiBrowzerRuntime.awaitInitializationComplete();

window.zitiBrowzerRuntime.noActiveChannelDetectedEnabled = true;

window.zitiBrowzerRuntime.logger.trace( 'zitiFetch: entered for URL: ', url);

// If the browZerSession has expired, then tear everything down and reboot
Expand Down Expand Up @@ -1138,14 +1138,19 @@ const zitiFetch = async ( url, opts ) => {
}
else if (!url.toLowerCase().startsWith('http')) {

let href = window.location.href;
const substrings = href.split('/');
// We have a 'relative' URL

href = substrings.length === 1
? href // delimiter is not part of the string
: substrings.slice(0, -1).join('/');

href = href + '/' + url;
let href;

if (url.includes('/')) {
href = `${window.location.origin}/${url}`;
} else {
const substrings = window.location.pathname.split('/');
let pathname = substrings.length === 1
? window.location.pathname // delimiter is not part of the string
: substrings.slice(0, -1).join('/');
href = `${window.location.origin}${pathname}/${url}`;
}

let newUrl;
let baseURIUrl = new URL( href );
Expand Down
8 changes: 4 additions & 4 deletions yarn.lock
Original file line number Diff line number Diff line change
Expand Up @@ -1178,10 +1178,10 @@
"@types/emscripten" "^1.39.6"
"@wasmer/wasi" "^1.0.2"

"@openziti/ziti-browzer-core@^0.17.0":
version "0.17.0"
resolved "https://registry.yarnpkg.com/@openziti/ziti-browzer-core/-/ziti-browzer-core-0.17.0.tgz#7efbc63c84be542d3bb48cdd4f4f55255d5d175c"
integrity sha512-BEF2zh15jPbwo4uCbNUMO8D+jK/G1FpytxPN79jEU9kRPYsnGc2I5sFbfMEmhZDKPHeULOumXwp8x97zyjKR6w==
"@openziti/ziti-browzer-core@^0.17.1":
version "0.17.1"
resolved "https://registry.yarnpkg.com/@openziti/ziti-browzer-core/-/ziti-browzer-core-0.17.1.tgz#9684393fe6d89795af9a242f528768c0f38e2ce0"
integrity sha512-QjlHSrw1Da7Z4Xl2M+Fnx+hTXHMhdgHhG6cr+AaSR1aJRvuSF1NfTupsAmLvzZS1VHDnZqKNUbwAlYAZhfTF7A==
dependencies:
"@openziti/libcrypto-js" "^0.9.0"
"@openziti/ziti-browzer-edge-client" "^0.6.0"
Expand Down

0 comments on commit 37f06ed

Please sign in to comment.