Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commitd5c505e

Browse files
authored
Event: Only attach events to objects that accept data - for real
There was a check in jQuery.event.add that was supposed to make it a noopfor objects that don't accept data like text or comment nodes. The problem wasthe check was incorrect: it assumed `dataPriv.get( elem )` returns a falsyvalue for an `elem` that doesn't accept data but that's not the case - we getan empty object then. The check was changed to use `acceptData` directly.Fixesgh-4397Closesgh-4558
1 parent5a3e066 commitd5c505e

File tree

2 files changed

+12
-2
lines changed

2 files changed

+12
-2
lines changed

‎src/event.js

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import documentElement from "./var/documentElement.js";
44
importrnothtmlwhitefrom"./var/rnothtmlwhite.js";
55
importrcheckableTypefrom"./var/rcheckableType.js";
66
importslicefrom"./var/slice.js";
7+
importacceptDatafrom"./data/var/acceptData.js";
78
importdataPrivfrom"./data/var/dataPriv.js";
89
importnodeNamefrom"./core/nodeName.js";
910

@@ -109,8 +110,8 @@ jQuery.event = {
109110
special,handlers,type,namespaces,origType,
110111
elemData=dataPriv.get(elem);
111112

112-
//Don't attach events tonoData or text/comment nodes (but allow plain objects)
113-
if(!elemData){
113+
//Only attach events toobjects that accept data
114+
if(!acceptData(elem)){
114115
return;
115116
}
116117

‎test/unit/event.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2811,6 +2811,15 @@ QUnit.test( "preventDefault() on focusin does not throw exception", function( as
28112811
},QUnit.config.testTimeout/4||1000);
28122812
});
28132813

2814+
QUnit.test(".on('focus', fn) on a text node doesn't throw",function(assert){
2815+
assert.expect(1);
2816+
2817+
jQuery(document.createTextNode("text"))
2818+
.on("focus",function(){});
2819+
2820+
assert.ok(true,"No crash");
2821+
});
2822+
28142823
QUnit.test("Donor event interference",function(assert){
28152824
assert.expect(8);
28162825

0 commit comments

Comments
 (0)

[8]ページ先頭

©2009-2025 Movatter.jp