-
Notifications
You must be signed in to change notification settings - Fork 33
Add ?load= URL param; update URL on ROM selection #61
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -16,17 +16,36 @@ function loadRomData(name) { | |||||
| return request.response; | ||||||
| } | ||||||
|
|
||||||
| function updateUrl(params) { | ||||||
| const url = new URL(window.location.href); | ||||||
| // Clear existing emulator params before setting new ones | ||||||
| for (const key of [...url.searchParams.keys()]) { | ||||||
| url.searchParams.delete(key); | ||||||
| } | ||||||
| for (const [key, val] of Object.entries(params)) { | ||||||
| if (val !== null) url.searchParams.set(key, val); | ||||||
| } | ||||||
| history.replaceState(null, "", url); | ||||||
| } | ||||||
|
|
||||||
| function resetLoadAndStart(filename, romdata) { | ||||||
| miracle_reset(); | ||||||
| bus.loadRom(filename, romdata, debug_init); | ||||||
| hideRomChooser(); | ||||||
| start(); | ||||||
| updateUrl({ load: filename }); | ||||||
| } | ||||||
|
|
||||||
| function loadUploadFile(file) { | ||||||
| const reader = new FileReader(); | ||||||
| reader.onload = function () { | ||||||
| resetLoadAndStart(file.name, reader.result); | ||||||
| // Uploaded files use b64sms encoding for shareability | ||||||
|
||||||
| const b64 = btoa(reader.result); | ||||||
| miracle_reset(); | ||||||
| bus.loadRom(file.name, reader.result, debug_init); | ||||||
| hideRomChooser(); | ||||||
| start(); | ||||||
| updateUrl({ b64sms: b64 }); | ||||||
| }; | ||||||
| reader.readAsBinaryString(file); | ||||||
| } | ||||||
|
|
@@ -129,7 +148,13 @@ function go() { | |||||
|
|
||||||
| const parsedQuery = parseQuery(); | ||||||
| if (parsedQuery["b64sms"]) { | ||||||
| bus.loadRom("b64.sms", atob(parsedQuery["b64sms"]), debug_init); | ||||||
| const name = parsedQuery["load"] ?? "uploaded.sms"; | ||||||
|
||||||
| const name = parsedQuery["load"] ?? "uploaded.sms"; | |
| const name = parsedQuery["load"] || "uploaded.sms"; |
Outdated
Copilot
AI
Mar 3, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
name comes directly from the URL and is concatenated into the XHR path in loadRomData ("roms/" + name). With values like ../index.html this will request files outside the roms/ directory. If ?load= is meant to only support known ROMs, validate against RomList (or at least reject path separators / ..) before calling loadRomData.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
updateUrlrewrites the query string but leavesurl.hashintact. SinceparseQuery()merges?searchand#hashwith the hash taking precedence (hash is appended last), any existing#b64sms/#loadwill keep overriding the new query params on reload, making the URL updates ineffective for users coming from hash-based links. Consider clearingurl.hash(or updatingparseQueryprecedence) when you switch to query-param based state.