mirror of
https://github.com/jquery/jquery.git
synced 2025-01-10 18:24:24 +00:00
Fixes #13551. Guard against illegal data access by undefined elem-owner
Signed-off-by: Rick Waldron <waldron.rick@gmail.com>
This commit is contained in:
parent
91824bd292
commit
692afbcc5f
11
src/data.js
11
src/data.js
@ -85,7 +85,7 @@ Data.prototype = {
|
|||||||
// Either a valid cache is found, or will be created.
|
// Either a valid cache is found, or will be created.
|
||||||
// New caches will be created and the unlock returned,
|
// New caches will be created and the unlock returned,
|
||||||
// allowing direct access to the newly created
|
// allowing direct access to the newly created
|
||||||
// empty data object.
|
// empty data object. A valid owner object must be provided.
|
||||||
var cache = this.cache[ this.key( owner ) ];
|
var cache = this.cache[ this.key( owner ) ];
|
||||||
|
|
||||||
return key === undefined ?
|
return key === undefined ?
|
||||||
@ -255,9 +255,12 @@ jQuery.fn.extend({
|
|||||||
var data,
|
var data,
|
||||||
camelKey = jQuery.camelCase( key );
|
camelKey = jQuery.camelCase( key );
|
||||||
|
|
||||||
// Get the Data...
|
// The calling jQuery object (element matches) is not empty
|
||||||
if ( value === undefined ) {
|
// (and therefore has an element appears at this[0]) and the
|
||||||
|
// `value` parameter was not undefined. An empty jQuery object
|
||||||
|
// will result in `undefined` for elem = this[0] which will
|
||||||
|
// throw an exception if an attempt to read a data cache is made.
|
||||||
|
if ( elem && value === undefined ) {
|
||||||
// Attempt to get data from the cache
|
// Attempt to get data from the cache
|
||||||
// with the key as-is
|
// with the key as-is
|
||||||
data = data_user.get( elem, key );
|
data = data_user.get( elem, key );
|
||||||
|
@ -670,3 +670,14 @@ test( "JSON data- attributes can have newlines", function() {
|
|||||||
equal( x.data("some").foo, "bar", "got a JSON data- attribute with spaces" );
|
equal( x.data("some").foo, "bar", "got a JSON data- attribute with spaces" );
|
||||||
x.remove();
|
x.remove();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
test(".data doesn't throw when calling selection is empty. #13551", function() {
|
||||||
|
expect(1);
|
||||||
|
|
||||||
|
try {
|
||||||
|
jQuery( null ).data( "prop" );
|
||||||
|
ok( true, "jQuery(null).data('prop') does not throw" );
|
||||||
|
} catch ( e ) {
|
||||||
|
ok( false, e.message );
|
||||||
|
}
|
||||||
|
});
|
||||||
|
Loading…
Reference in New Issue
Block a user