Skip to content

Commit

Permalink
Encode keys in URLs to support keys with characters that aren't valid…
Browse files Browse the repository at this point in the history
… in URLs

Signed-off-by: Caleb Schoepp <[email protected]>
  • Loading branch information
calebschoepp committed Mar 10, 2023
1 parent d921a9d commit 1657374
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 4 deletions.
4 changes: 2 additions & 2 deletions explorer/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ router.get("/internal/kv-explorer/api/stores/:store", async (req): Promise<HttpR

router.get("/internal/kv-explorer/api/stores/:store/keys/:key", async (req): Promise<HttpResponse> => {
let store = req.params.store;
let key = req.params.key;
let key = decodeURIComponent(req.params.key);
console.log(`Getting the value of key ${key} from store: ${store}`);

try {
Expand All @@ -62,7 +62,7 @@ router.get("/internal/kv-explorer/api/stores/:store/keys/:key", async (req): Pro

router.delete("/internal/kv-explorer/api/stores/:store/keys/:key", async req => {
let store = req.params.store;
let key = req.params.key;
let key = decodeURIComponent(req.params.key);

console.log(`Deleting the value of key ${key} from store: ${store}`);

Expand Down
4 changes: 2 additions & 2 deletions explorer/src/page.ts
Original file line number Diff line number Diff line change
Expand Up @@ -291,7 +291,7 @@ export function html(): string {
$(\`#\${hashedKey}View\`).click(function () {
var key = $(this).data("key");
fetch(\`/internal/kv-explorer/api/stores/default/keys/\${key}\`).then((response) => response.json()).then((data) => {
fetch(\`/internal/kv-explorer/api/stores/default/keys/\${encodeURIComponent(key)}\`).then((response) => response.json()).then((data) => {
let decoder = new TextDecoder();
let value = decoder.decode(new Uint8Array(data.value));
$("#valueContent").text(value);
Expand All @@ -302,7 +302,7 @@ export function html(): string {
$(\`#\${hashedKey}Delete\`).click(function () {
var key = $(this).data("key");
fetch(\`/internal/kv-explorer/api/stores/default/keys/\${key}\`, {
fetch(\`/internal/kv-explorer/api/stores/default/keys/\${encodeURIComponent(key)}\`, {
method: 'DELETE',
})
.then(() => {
Expand Down

0 comments on commit 1657374

Please sign in to comment.