Skip to content

Commit

Permalink
Change encoding/deconding from using atob to encodeURIComponent-based
Browse files Browse the repository at this point in the history
  • Loading branch information
carlopi committed Dec 14, 2023
1 parent 53abd4b commit 9f52a2a
Showing 1 changed file with 20 additions and 2 deletions.
22 changes: 20 additions & 2 deletions packages/duckdb-wasm-shell/src/shell.ts
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,7 @@ class ShellRuntime {
}
public async pushInputToHistory(this: ShellRuntime, value: string) {
var hash = window.location.hash;
const encode = btoa(value);
const encode = encodeURIComponent(extraswaps(value));
if (hash === "")
hash = "queries=v0";
hash += ",";
Expand All @@ -77,6 +77,24 @@ function formatBytes(value: number): string {
return `${size} ${exp ? `${k}MGTPEZY`[exp - 1] + suffix : `byte${size !== 1 ? 's' : ''}`}`;
}

function extraswaps(input: string): string {
// As long as this function is symmetrical, all good
let res : string = "";
for (let i=0; i<input.length; i++) {
if (input[i] == ' ')
res += '-';
else if (input[i] == '-')
res += ' ';
else if (input[i] == ';')
res += '~';
else if (input[i] == '~')
res += ';';
else
res += input[i];
}
return res;
}

export async function embed(props: ShellProps) {
// Initialize the shell
await shell.default(props.shellModule);
Expand Down Expand Up @@ -128,7 +146,7 @@ export async function embed(props: ShellProps) {
var splits = hash.split(',');
var sqls : Array<string> = [];
for (var i=1; i< splits.length; i++) {
sqls.push( atob(splits[i]));
sqls.push(extraswaps(decodeURIComponent(splits[i])));
}
window.location.hash="";
await step('Rewinding history!', async () => {
Expand Down

0 comments on commit 9f52a2a

Please sign in to comment.