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