Skip to content

[Bug]: parseKeybindingShortcut silently compiles trailing-"+" typos (e.g. "mod+", "ctrl+shift+", "mod+++") as "+" shortcuts instead of rejecting them #41225

Closed

Description

@gpu004

What I observed

parseKeybindingShortcut (packages/shared/src/keybindings.ts:159-176) checks if (trailingEmptyCount > 0) instead of trailingEmptyCount === 2 after splitting on "+" and popping trailing empty tokens.

As a result, malformed or incomplete shortcuts with a dangling "+" ("mod+", "ctrl+shift+"), extra "+"es ("mod+++", "+++"), or empty/whitespace strings ("", " ") all silently compile into a valid shortcut with key: "+". (This also makes the if (tokens.length === 0) return null; guard on line 176 unreachable.)

When a user hand-edits ~/.t3/userdata/keybindings.json and leaves a typo like {"key": "mod+", "command": "sidebar.toggle"}, T3 Code emits no keybindings.invalid-entry warning, silently drops the command's default binding (mod+b), and binds Cmd/Ctrl + + (colliding with preview.zoomIn's default mod++).

Reproduction

  • Commit: main @ 9d3054a7bb
  • Environment: macOS 27.2.1, Node v26.13.1

Run from the repo root:

node --experimental-strip-types -e '
import {
  compileResolvedKeybindingRule,
  mergeWithDefaultKeybindings,
  parseKeybindingShortcut,
} from "./packages/shared/src/keybindings.ts";

for (const key of ["", "   ", "mod+", "ctrl+shift+", "mod+++", "+++"]) {
  console.log(JSON.stringify(key), "->", parseKeybindingShortcut(key));
}
const compiled = compileResolvedKeybindingRule({ key: "mod+", command: "sidebar.toggle" });
const merged = mergeWithDefaultKeybindings(compiled ? [compiled] : []);
console.log("sidebar.toggle:", merged.filter((b) => b.command === "sidebar.toggle"));
'

Expected behavior

Only "+" (["", ""], trailingEmptyCount === 2) and "<modifiers>++" ([...mods, "", ""], trailingEmptyCount === 2) parse to key: "+" (matching DEFAULT_KEYBINDINGS and encodeShortcut). Incomplete or malformed strings ("", " ", "mod+", "ctrl+shift+", "mod+++", "+++") should return null so apps/server/src/keybindings.ts surfaces a keybindings.invalid-entry warning and preserves the command's default binding.

Actual behavior

Every trailing-+ or empty string compiles into { key: "+" }, passes KeybindingRule / ResolvedKeybindingFromConfig validation without warning, and replaces the command's default shortcut in mergeWithDefaultKeybindings.

Evidence

Output from the command above:

""            -> { key: '+', metaKey: false, ctrlKey: false, shiftKey: false, altKey: false, modKey: false }
"   "         -> { key: '+', metaKey: false, ctrlKey: false, shiftKey: false, altKey: false, modKey: false }
"mod+"        -> { key: '+', metaKey: false, ctrlKey: false, shiftKey: false, altKey: false, modKey: true }
"ctrl+shift+" -> { key: '+', metaKey: false, ctrlKey: true, shiftKey: true, altKey: false, modKey: false }
"mod+++"      -> { key: '+', metaKey: false, ctrlKey: false, shiftKey: false, altKey: false, modKey: true }
"+++"         -> { key: '+', metaKey: false, ctrlKey: false, shiftKey: false, altKey: false, modKey: false }
sidebar.toggle: [
  { command: 'sidebar.toggle', shortcut: { key: '+', metaKey: false, ctrlKey: false, shiftKey: false, altKey: false, modKey: true } }
]

Additional investigation

  • How found: Property-based testing of packages/shared parsers, minimized to the plain Node snippet above.
  • Verified: Confirmed on origin/main (9d3054a7bb); apps/server/src/keybindings.ts (loadRuntimeCustomKeybindingsConfig) accepts "mod+", "ctrl+shift+", and "mod+++" through KeybindingRule (KeybindingValue) and compiles them via compileResolvedKeybindingRule → parseKeybindingShortcut.
  • Duplicate check: Searched open and closed issues/PRs for parseKeybindingShortcut, keybinding trailing plus, keybindings.json mod+, and keybinding plus — no matching issue found.
  • Impact: Minor — typos in keybindings.json silently drop default bindings and bind + without any validation warning.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions