Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix: Prefix the sessionStorage data with pathname #279

Merged
merged 1 commit into from
Jan 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 2 additions & 7 deletions html5/connect.html
Original file line number Diff line number Diff line change
Expand Up @@ -617,12 +617,7 @@ <h4 class="panel-title">Advanced options</h4>

function add_prop(prop, value, first) {
if (Utilities.hasSessionStorage()) {
//we're using sessionStorage, no need for URL
if (value === null || value === "undefined") {
sessionStorage.removeItem(prop);
} else {
sessionStorage.setItem(prop, value);
}
Utilities.setSessionStorageValue(prop, value);
return "";
}
if (value === null || value === "undefined") {
Expand Down Expand Up @@ -1618,7 +1613,7 @@ <h4 class="panel-title">Advanced options</h4>
});
//delete session params:
try {
sessionStorage.clear();
Utilities.clearSessionStorage();
} catch (e) {
//ignore
}
Expand Down
10 changes: 3 additions & 7 deletions html5/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -793,12 +793,12 @@ <h2>Xpra Bug Report</h2>
}

try {
sessionStorage.removeItem("password");
Utilities.setSessionStorageValue("password",null);
} catch (e) {
//ignore
}
try {
sessionStorage.removeItem("token");
Utilities.setSessionStorageValue("token",null);
} catch (e) {
//ignore
}
Expand Down Expand Up @@ -1033,11 +1033,7 @@ <h2>Xpra Bug Report</h2>
const has_session_storage = Utilities.hasSessionStorage();
function add_prop(prop, value) {
if (has_session_storage) {
if (value === null || value === "undefined") {
sessionStorage.removeItem(prop);
} else {
sessionStorage.setItem(prop, value);
}
Utilities.setSessionStorageValue(prop, value);
} else {
if (value === null || value === "undefined") {
value = "";
Expand Down
32 changes: 29 additions & 3 deletions html5/js/Utilities.js
Original file line number Diff line number Diff line change
Expand Up @@ -590,9 +590,7 @@ const Utilities = {
}
let value = getParameter(property);
try {
if (value === undefined && typeof sessionStorage !== "undefined") {
value = sessionStorage.getItem(property);
}
value = Utilities.getSessionStorageValue(property);
} catch {
value = null;
}
Expand Down Expand Up @@ -623,6 +621,34 @@ const Utilities = {
}
},

getSessionStorageValue(property) {
const params = JSON.parse(sessionStorage.getItem(Utilities.getSessionStoragePrefix()))
if (property in params) {
return String(params[property]);
}
return null;
},

setSessionStorageValue(property, value) {
const prefix = Utilities.getSessionStoragePrefix();
let params = JSON.parse(sessionStorage.getItem(prefix)) || {}
if (value === null || value === "undefined") {
delete params[property];
} else {
params[property] = String(value);
}
sessionStorage.setItem(prefix, JSON.stringify(params));
},

clearSessionStorage() {
sessionStorage.removeItem(Utilities.getSessionStoragePrefix());
},

getSessionStoragePrefix() {
const urlPath = new URL(window.location.href).pathname
return urlPath.substring(0, urlPath.lastIndexOf("/"));
},

totaam marked this conversation as resolved.
Show resolved Hide resolved
getConnectionInfo() {
if (!Object.hasOwn(navigator, "connection")) {
return {};
Expand Down