From 38f078e22959e3c79c94e61b2b9d1eb13021181f Mon Sep 17 00:00:00 2001 From: ShashankaNataraj Date: Mon, 19 Aug 2019 15:46:15 +0530 Subject: [PATCH 1/6] Fixes #4363 --- src/core.js | 6 +----- src/deprecated.js | 8 ++++++-- test/unit/core.js | 22 ---------------------- test/unit/deprecated.js | 22 ++++++++++++++++++++++ 4 files changed, 29 insertions(+), 29 deletions(-) diff --git a/src/core.js b/src/core.js index fdc32dde83..01f501d210 100644 --- a/src/core.js +++ b/src/core.js @@ -14,14 +14,13 @@ define( [ "./var/hasOwn", "./var/fnToString", "./var/ObjectFunctionString", - "./var/trim", "./var/support", "./var/isWindow", "./core/DOMEval", "./core/toType" ], function( arr, getProto, slice, concat, push, indexOf, class2type, toString, hasOwn, fnToString, ObjectFunctionString, - trim, support, isWindow, DOMEval, toType ) { + support, isWindow, DOMEval, toType ) { "use strict"; @@ -298,9 +297,6 @@ jQuery.extend( { return ret; }, - trim: function( text ) { - return text == null ? "" : trim.call( text ); - }, // results is for internal usage only makeArray: function( arr, results ) { diff --git a/src/deprecated.js b/src/deprecated.js index 4edefaca07..6ca79d514a 100644 --- a/src/deprecated.js +++ b/src/deprecated.js @@ -1,9 +1,9 @@ define( [ "./core", "./var/slice", - + "./var/trim", "./event/alias" -], function( jQuery, slice ) { +], function( jQuery, trim, slice ) { "use strict"; @@ -66,4 +66,8 @@ jQuery.holdReady = function( hold ) { jQuery.ready( true ); } }; + +jQuery.trim = function( text ) { + return text == null ? "" : trim.call( text ); +}; } ); diff --git a/test/unit/core.js b/test/unit/core.js index c7532df478..ca644fe20e 100644 --- a/test/unit/core.js +++ b/test/unit/core.js @@ -216,28 +216,6 @@ QUnit.test( "noConflict", function( assert ) { window[ "jQuery" ] = jQuery = $$; } ); -QUnit.test( "trim", function( assert ) { - assert.expect( 13 ); - - var nbsp = String.fromCharCode( 160 ); - - assert.equal( jQuery.trim( "hello " ), "hello", "trailing space" ); - assert.equal( jQuery.trim( " hello" ), "hello", "leading space" ); - assert.equal( jQuery.trim( " hello " ), "hello", "space on both sides" ); - assert.equal( jQuery.trim( " " + nbsp + "hello " + nbsp + " " ), "hello", " " ); - - assert.equal( jQuery.trim(), "", "Nothing in." ); - assert.equal( jQuery.trim( undefined ), "", "Undefined" ); - assert.equal( jQuery.trim( null ), "", "Null" ); - assert.equal( jQuery.trim( 5 ), "5", "Number" ); - assert.equal( jQuery.trim( false ), "false", "Boolean" ); - - assert.equal( jQuery.trim( " " ), "", "space should be trimmed" ); - assert.equal( jQuery.trim( "ipad\xA0" ), "ipad", "nbsp should be trimmed" ); - assert.equal( jQuery.trim( "\uFEFF" ), "", "zwsp should be trimmed" ); - assert.equal( jQuery.trim( "\uFEFF \xA0! | \uFEFF" ), "! |", "leading/trailing should be trimmed" ); -} ); - QUnit.test( "isPlainObject", function( assert ) { var done = assert.async(); diff --git a/test/unit/deprecated.js b/test/unit/deprecated.js index c0ebf19d61..df9d5ffa85 100644 --- a/test/unit/deprecated.js +++ b/test/unit/deprecated.js @@ -160,3 +160,25 @@ QUnit.test( "jQuery.proxy", function( assert ) { cb = jQuery.proxy( fn, null, "arg1", "arg2" ); cb.call( thisObject, "arg3" ); } ); + +QUnit.test( "trim", function( assert ) { + assert.expect( 13 ); + + var nbsp = String.fromCharCode( 160 ); + + assert.equal( jQuery.trim( "hello " ), "hello", "trailing space" ); + assert.equal( jQuery.trim( " hello" ), "hello", "leading space" ); + assert.equal( jQuery.trim( " hello " ), "hello", "space on both sides" ); + assert.equal( jQuery.trim( " " + nbsp + "hello " + nbsp + " " ), "hello", " " ); + + assert.equal( jQuery.trim(), "", "Nothing in." ); + assert.equal( jQuery.trim( undefined ), "", "Undefined" ); + assert.equal( jQuery.trim( null ), "", "Null" ); + assert.equal( jQuery.trim( 5 ), "5", "Number" ); + assert.equal( jQuery.trim( false ), "false", "Boolean" ); + + assert.equal( jQuery.trim( " " ), "", "space should be trimmed" ); + assert.equal( jQuery.trim( "ipad\xA0" ), "ipad", "nbsp should be trimmed" ); + assert.equal( jQuery.trim( "\uFEFF" ), "", "zwsp should be trimmed" ); + assert.equal( jQuery.trim( "\uFEFF \xA0! | \uFEFF" ), "! |", "leading/trailing should be trimmed" ); +} ); From cdcb2efb326212a1b4cab51bb9f519895004e651 Mon Sep 17 00:00:00 2001 From: Shashanka N Date: Mon, 19 Aug 2019 16:02:16 +0530 Subject: [PATCH 2/6] Fixes #4363 --- src/deprecated.js | 1 + 1 file changed, 1 insertion(+) diff --git a/src/deprecated.js b/src/deprecated.js index 6ca79d514a..69def0cf6c 100644 --- a/src/deprecated.js +++ b/src/deprecated.js @@ -70,4 +70,5 @@ jQuery.holdReady = function( hold ) { jQuery.trim = function( text ) { return text == null ? "" : trim.call( text ); }; + } ); From 03fce6af21a2a506d7c196189722864369b745f1 Mon Sep 17 00:00:00 2001 From: ShashankaNataraj Date: Mon, 19 Aug 2019 16:09:29 +0530 Subject: [PATCH 3/6] Fixes #4363 --- src/deprecated.js | 1 - 1 file changed, 1 deletion(-) diff --git a/src/deprecated.js b/src/deprecated.js index 69def0cf6c..6ca79d514a 100644 --- a/src/deprecated.js +++ b/src/deprecated.js @@ -70,5 +70,4 @@ jQuery.holdReady = function( hold ) { jQuery.trim = function( text ) { return text == null ? "" : trim.call( text ); }; - } ); From d3c1bcc190fe6482daafebda97f83643bab7fe34 Mon Sep 17 00:00:00 2001 From: Shashanka N Date: Mon, 19 Aug 2019 16:09:29 +0530 Subject: [PATCH 4/6] Fixes #4363 From 5fc24a3ef37327083b8a2c950409e5daa7dd3792 Mon Sep 17 00:00:00 2001 From: Shashanka N Date: Tue, 20 Aug 2019 09:33:49 +0530 Subject: [PATCH 5/6] Fixes #4363 - removed the trim test as per review comment --- test/unit/basic.js | 1 - 1 file changed, 1 deletion(-) diff --git a/test/unit/basic.js b/test/unit/basic.js index 8b567f1957..bbc2e44fdf 100644 --- a/test/unit/basic.js +++ b/test/unit/basic.js @@ -81,7 +81,6 @@ QUnit.test( "core", function( assert ) { var elem = jQuery( "
" ); assert.strictEqual( elem.length, 2, "Correct number of elements" ); - assert.strictEqual( jQuery.trim( " hello " ), "hello", "jQuery.trim" ); assert.ok( jQuery.isPlainObject( { "a": 2 } ), "jQuery.isPlainObject(object)" ); assert.ok( !jQuery.isPlainObject( "foo" ), "jQuery.isPlainObject(String)" ); From 14954ad65667b9a628f9382481a9204912b9b12c Mon Sep 17 00:00:00 2001 From: Shashanka N Date: Tue, 20 Aug 2019 09:45:46 +0530 Subject: [PATCH 6/6] Fixes #4363 - Changed assert count to get tests to pass --- test/unit/basic.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/unit/basic.js b/test/unit/basic.js index bbc2e44fdf..79a0610ddc 100644 --- a/test/unit/basic.js +++ b/test/unit/basic.js @@ -76,7 +76,7 @@ QUnit.test( "show/hide", function( assert ) { } QUnit.test( "core", function( assert ) { - assert.expect( 18 ); + assert.expect( 17 ); var elem = jQuery( "
" );