Skip to content
This repository has been archived by the owner on Sep 16, 2022. It is now read-only.

Commit

Permalink
fix(Core): composite key event bindings ignore synthetic events to av…
Browse files Browse the repository at this point in the history
…oid crash

The `KeyEventsPlugin` responsible for handling composite key event bindings,
such as `(keyup.enter)`, will now ignore any events that aren't a real
`KeyBoardEvent`. Previously the plugin assumed all events were so that it could
access the `keyCode` property. This would lead to a crash in the event that a
synthetic or custom event with the same `type` was dispatched on the element.

Fixes #1694.

PiperOrigin-RevId: 229279612
  • Loading branch information
leonsenft authored and alorenzen committed Jan 17, 2019
1 parent 3f2a5fa commit 0cd6572
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 1 deletion.
6 changes: 6 additions & 0 deletions angular/CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@
* The template compiler now outputs the full path to a template file when it
reports an error.

* [#1694][]: Composite `keyup` and `keydown` event bindings now ignore
synthetic events (e.g. those triggered by a mouse click) instead of throwing
a `TypeError`.

[#1694]: https://github.com/dart-lang/angular/issues/1694

## 5.2.0

### Breaking changes
Expand Down
6 changes: 5 additions & 1 deletion angular/lib/src/platform/dom/events/key_events.dart
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,11 @@ class KeyEventsPlugin extends EventManagerPlugin {
static Function _eventCallback(
dynamic element, String fullKey, Function handler) {
return (event) {
if (_getEventFullKey(event as KeyboardEvent) == fullKey) {
// Check that the event is a real `KeyboardEvent` and not a synthetic
// event that happens to be share the same `type` property. This ensures
// that the event has a `keyCode` property we can use to construct the
// full key name.
if (event is KeyboardEvent && _getEventFullKey(event) == fullKey) {
handler(event);
}
};
Expand Down

0 comments on commit 0cd6572

Please sign in to comment.