diff --git a/src/jquery/core.js b/src/jquery/core.js index e67b5782..465cf6c1 100644 --- a/src/jquery/core.js +++ b/src/jquery/core.js @@ -15,9 +15,9 @@ var findProp, rattrHashTest = /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/, rattrHashGlob = /\[(\s*[-\w]+\s*)([~|^$*]?=)\s*([-\w#]*?#[-\w#]*)\s*\]/g, - // Support: Android <=4.0 only - // Make sure we trim BOM and NBSP - rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g; + // Require that the "whitespace run" starts from a non-whitespace + // to avoid O(N^2) behavior when the engine would try matching "\s+$" at each space position. + rtrim = /^[\s\uFEFF\xA0]+|([^\s\uFEFF\xA0])[\s\uFEFF\xA0]+$/g; migratePatchFunc( jQuery.fn, "init", function( arg1 ) { var args = Array.prototype.slice.call( arguments ); @@ -109,7 +109,7 @@ if ( jQueryVersionSince( "3.1.1" ) ) { migratePatchAndWarnFunc( jQuery, "trim", function( text ) { return text == null ? "" : - ( text + "" ).replace( rtrim, "" ); + ( text + "" ).replace( rtrim, "$1" ); }, "trim", "jQuery.trim is deprecated; use String.prototype.trim" ); }