diff options
author | Jakub Berkop <32750982+Safffatttu@users.noreply.github.com> | 2020-11-23 18:41:15 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-11-23 18:41:15 +0100 |
commit | c6bb3d452a4f2b504c7d77263f811f1d019ac05f (patch) | |
tree | 5f99a687a8ce64ccb01bbd21d1c454fbc5b65e30 /Libraries | |
parent | e7e179212c5b1938fd00da62a1d5aca8441cf487 (diff) | |
download | serenity-c6bb3d452a4f2b504c7d77263f811f1d019ac05f.zip |
LibGUI: Widget::action_for_key_event() should fail for invalid shortcuts (#4137)
Previously GUI::Actions which were constructed without initializing
m_shortcut could be activated via an invalid GUI::Shortcut.
Steps to reproduce:
It was possible to enable TextEditor's markdown preview by pressing
Ctrl or Alt (Cmd/Ctrl) keys, which should not happen, as this Action
did not specify a shortcut.
This fix should apply to all other cases where actions where declared
without specifying a shortcut.
Diffstat (limited to 'Libraries')
-rw-r--r-- | Libraries/LibGUI/Widget.cpp | 5 |
1 files changed, 5 insertions, 0 deletions
diff --git a/Libraries/LibGUI/Widget.cpp b/Libraries/LibGUI/Widget.cpp index 10a21e0fe8..9c5cb721f5 100644 --- a/Libraries/LibGUI/Widget.cpp +++ b/Libraries/LibGUI/Widget.cpp @@ -739,6 +739,11 @@ bool Widget::is_backmost() const Action* Widget::action_for_key_event(const KeyEvent& event) { Shortcut shortcut(event.modifiers(), (KeyCode)event.key()); + + if (!shortcut.is_valid()) { + return nullptr; + } + Action* found_action = nullptr; for_each_child_of_type<Action>([&](auto& action) { if (action.shortcut() == shortcut) { |