fix(extension-api): reject key chords with empty + segments - #912
Open
Rehan30g wants to merge 1 commit into
Open
fix(extension-api): reject key chords with empty + segments#912Rehan30g wants to merge 1 commit into
Rehan30g wants to merge 1 commit into
Conversation
The shared chord parser filtered out empty tokens after splitting on "+", so malformed bindings like "s+", "+s", "ctrl++s", and "ctrl+s+" were silently normalized into a different valid shortcut instead of being rejected. A typo could therefore claim and fire a real keybinding. Recognize the literal "+" chord before empty segments are rejected, then treat any other empty segment around "+" as a parse error. This keeps "+" and " + " valid while making parseKeyChord reject malformed chords consistently with its existing handling of "ctrl+" and "ctlr+s". Fixes modem-dev#906
Contributor
|
PR author is not in the allowed authors list. |
|
@Rehan30g is attempting to deploy a commit to the Modem Team on Vercel. A member of the Team first needs to authorize it. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The shared key-chord parser (
parseKeyChordinsrc/extension-api/keys.ts) split a chord on+and filtered out any empty tokens before validating modifier/base-key structure. That let malformed bindings silently resolve to a different, valid shortcut:parseKeyChord("s+")returned the same parsed chord asparseKeyChord("s"), so a typo in a user[keybindings]entry, an extensionregisterCommandbinding, or the publicmatchesKeyhelper could claim and fire a real shortcut instead of being rejected. This was inconsistent with the parser's existing behavior for other malformed chords likectlr+s,f13, andctrl+, which are already rejected.Fix
Recognize the literal
+chord (optionally whitespace-padded, e.g." + ") before empty-segment rejection, since splitting it on+produces two empty segments that are intentional. For every other chord, split on+, trim each segment, and return a parse error if any segment is empty instead of silently dropping it. Whitespace-padded valid chords such asctrl + scontinue to parse.The fix lives entirely in the shared grammar in
src/extension-api/keys.ts, so built-in commands, user keybindings, extensionregisterCommandbindings, and the publicmatchesKeyhelper all inherit the stricter validation from one place.Tests
src/extension-api/keys.test.ts: added table-driven coverage assertings+,+s,ctrl++s, andctrl+s+are rejected, and that+," + ", andctrl + sstill parse correctly.src/ui/lib/keymap.test.ts: added a case confirming a malformed chord with an empty+segment (s+) does not claim another command's real shortcut (s) and is reported as one keybinding issue while its valid sibling chord survives.Validation
A patch Changeset for
hunkdiffis included.Fixes #906