root / drupal7 / misc / jquery-extend-3.4.0.js @ bd0d4c5c
1 |
/**
|
---|---|
2 |
* For jQuery versions less than 3.4.0, this replaces the jQuery.extend
|
3 |
* function with the one from jQuery 3.4.0, slightly modified (documented
|
4 |
* below) to be compatible with older jQuery versions and browsers.
|
5 |
*
|
6 |
* This provides the Object.prototype pollution vulnerability fix to Drupal
|
7 |
* installations running older jQuery versions, including the versions shipped
|
8 |
* with Drupal core and https://www.drupal.org/project/jquery_update.
|
9 |
*
|
10 |
* @see https://github.com/jquery/jquery/pull/4333
|
11 |
*/
|
12 |
|
13 |
(function (jQuery) {
|
14 |
|
15 |
// Do not override jQuery.extend() if the jQuery version is already >=3.4.0.
|
16 |
var versionParts = jQuery.fn.jquery.split('.'); |
17 |
var majorVersion = parseInt(versionParts[0]); |
18 |
var minorVersion = parseInt(versionParts[1]); |
19 |
var patchVersion = parseInt(versionParts[2]); |
20 |
var isPreReleaseVersion = (patchVersion.toString() !== versionParts[2]); |
21 |
if (
|
22 |
(majorVersion > 3) ||
|
23 |
(majorVersion === 3 && minorVersion > 4) || |
24 |
(majorVersion === 3 && minorVersion === 4 && patchVersion > 0) || |
25 |
(majorVersion === 3 && minorVersion === 4 && patchVersion === 0 && !isPreReleaseVersion) |
26 |
) { |
27 |
return;
|
28 |
} |
29 |
|
30 |
/**
|
31 |
* This is almost verbatim copied from jQuery 3.4.0.
|
32 |
*
|
33 |
* Only two minor changes have been made:
|
34 |
* - The call to isFunction() is changed to jQuery.isFunction().
|
35 |
* - The two calls to Array.isArray() is changed to jQuery.isArray().
|
36 |
*
|
37 |
* The above two changes ensure compatibility with all older jQuery versions
|
38 |
* (1.4.4 - 3.3.1) and older browser versions (e.g., IE8).
|
39 |
*/
|
40 |
jQuery.extend = jQuery.fn.extend = function() { |
41 |
var options, name, src, copy, copyIsArray, clone,
|
42 |
target = arguments[ 0 ] || {}, |
43 |
i = 1,
|
44 |
length = arguments.length,
|
45 |
deep = false;
|
46 |
|
47 |
// Handle a deep copy situation
|
48 |
if ( typeof target === "boolean" ) { |
49 |
deep = target; |
50 |
|
51 |
// Skip the boolean and the target
|
52 |
target = arguments[ i ] || {};
|
53 |
i++; |
54 |
} |
55 |
|
56 |
// Handle case when target is a string or something (possible in deep copy)
|
57 |
if ( typeof target !== "object" && !jQuery.isFunction( target ) ) { |
58 |
target = {}; |
59 |
} |
60 |
|
61 |
// Extend jQuery itself if only one argument is passed
|
62 |
if ( i === length ) {
|
63 |
target = this;
|
64 |
i--; |
65 |
} |
66 |
|
67 |
for ( ; i < length; i++ ) {
|
68 |
|
69 |
// Only deal with non-null/undefined values
|
70 |
if ( ( options = arguments[ i ] ) != null ) { |
71 |
|
72 |
// Extend the base object
|
73 |
for ( name in options ) { |
74 |
copy = options[ name ]; |
75 |
|
76 |
// Prevent Object.prototype pollution
|
77 |
// Prevent never-ending loop
|
78 |
if ( name === "__proto__" || target === copy ) { |
79 |
continue;
|
80 |
} |
81 |
|
82 |
// Recurse if we're merging plain objects or arrays
|
83 |
if ( deep && copy && ( jQuery.isPlainObject( copy ) ||
|
84 |
( copyIsArray = jQuery.isArray( copy ) ) ) ) { |
85 |
src = target[ name ]; |
86 |
|
87 |
// Ensure proper type for the source value
|
88 |
if ( copyIsArray && !jQuery.isArray( src ) ) {
|
89 |
clone = []; |
90 |
} else if ( !copyIsArray && !jQuery.isPlainObject( src ) ) { |
91 |
clone = {}; |
92 |
} else {
|
93 |
clone = src; |
94 |
} |
95 |
copyIsArray = false;
|
96 |
|
97 |
// Never move original objects, clone them
|
98 |
target[ name ] = jQuery.extend( deep, clone, copy ); |
99 |
|
100 |
// Don't bring in undefined values
|
101 |
} else if ( copy !== undefined ) { |
102 |
target[ name ] = copy; |
103 |
} |
104 |
} |
105 |
} |
106 |
} |
107 |
|
108 |
// Return the modified object
|
109 |
return target;
|
110 |
}; |
111 |
|
112 |
})(jQuery); |