Skip to content

Keyboard shortcuts fire on Cmd+R/Ctrl+R; raw shortcut produces 404 on /md/{id} pages #208

@dominikroblek

Description

@dominikroblek

Summary

Two related bugs in paste.js:

  1. The keyboard handlers for n, r, y, d, q, p, w, m, ? don't filter modifier keys, so Cmd+R (or Ctrl+R) fires the wastebin r shortcut alongside the browser reload. The c handler at the bottom of onKey correctly filters with && !(e.ctrlKey || e.metaKey) — that fix from Honor selection for copying via Ctrl-C? #159 was never propagated to the other shortcuts.
  2. The r/d/q shortcuts compose their target URL by prepending /raw, /dl, /qr to window.location.pathname. On /md/{id} pages this produces /raw/md/{id}, which 404s. The correct raw URL is /raw/{id} (no md/ segment) — that one returns 200.

These compound into the user-visible failure: Cmd+R on /md/{id} navigates to a 404 instead of reloading the rendered view.

Repro

  1. Create a Markdown paste (extension md).
  2. Open the rendered view: /md/{id}.
  3. Press Cmd+R (macOS) or Ctrl+R (Linux/Windows).
  4. URL becomes /raw/md/{id} → 404.

Expected

  • Browser reload leaves the page on /md/{id} and re-renders.
  • Even with the plain r shortcut, the raw target on a /md/{id} page should be /raw/{id}, not /raw/md/{id}.

Source pointers (paste.js)

```js
function onKey(e) {
if (e.key == 'n') { // missing modifier filter
window.location.href = "/";
}
else if (e.key == 'r') { // missing modifier filter
window.location.href = "/raw" + window.location.pathname; // wrong on /md/{id}
}
...
else if (e.key == 'd') { // same bugs
window.location.href = "/dl" + window.location.pathname;
}
else if (e.key == 'q') { // same bugs
window.location.href = "/qr" + window.location.pathname;
}
else if (e.key == 'c' && !(e.ctrlKey || e.metaKey)) { // correct (post-#159)
copy();
}
...
}
```

Suggested fix

  • Apply the `&& !(e.ctrlKey || e.metaKey)` filter (from the `c` handler) to all unmodified-key shortcuts.
  • Derive the `/raw`, `/dl`, `/qr` targets from the paste id rather than `location.pathname` — e.g. expose the id as `data-paste-id` on `` and read it in the handler.

Tested on wastebin 3.6.1.

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions