🌐 AI搜索 & 代理 主页
Skip to content

Commit 56e73e0

Browse files
ShashankaNatarajmgol
authored andcommitted
Core: Deprecate jQuery.trim
Fixes gh-4363 Closes gh-4461 (cherry picked from 5ea5946)
1 parent 2f666c1 commit 56e73e0

File tree

5 files changed

+33
-36
lines changed

5 files changed

+33
-36
lines changed

src/core.js

Lines changed: 1 addition & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,7 @@ var
3434
// The jQuery object is actually just the init constructor 'enhanced'
3535
// Need init if jQuery is called (just allow error to be thrown if not included)
3636
return new jQuery.fn.init( selector, context );
37-
},
38-
39-
// Support: Android <=4.0 only
40-
// Make sure we trim BOM and NBSP
41-
rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
37+
};
4238

4339
jQuery.fn = jQuery.prototype = {
4440

@@ -275,13 +271,6 @@ jQuery.extend( {
275271
return obj;
276272
},
277273

278-
// Support: Android <=4.0 only
279-
trim: function( text ) {
280-
return text == null ?
281-
"" :
282-
( text + "" ).replace( rtrim, "" );
283-
},
284-
285274
// results is for internal usage only
286275
makeArray: function( arr, results ) {
287276
var ret = results || [];

src/deprecated.js

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@ define( [
1212

1313
"use strict";
1414

15+
// Support: Android <=4.0 only
16+
// Make sure we trim BOM and NBSP
17+
var rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g;
18+
1519
jQuery.fn.extend( {
1620

1721
bind: function( types, data, fn ) {
@@ -95,4 +99,9 @@ jQuery.isNumeric = function( obj ) {
9599
!isNaN( obj - parseFloat( obj ) );
96100
};
97101

102+
jQuery.trim = function( text ) {
103+
return text == null ?
104+
"" :
105+
( text + "" ).replace( rtrim, "" );
106+
};
98107
} );

test/unit/basic.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -76,12 +76,11 @@ QUnit.test( "show/hide", function( assert ) {
7676
}
7777

7878
QUnit.test( "core", function( assert ) {
79-
assert.expect( 18 );
79+
assert.expect( 17 );
8080

8181
var elem = jQuery( "<div></div><span></span>" );
8282

8383
assert.strictEqual( elem.length, 2, "Correct number of elements" );
84-
assert.strictEqual( jQuery.trim( " hello " ), "hello", "jQuery.trim" );
8584

8685
assert.ok( jQuery.isPlainObject( { "a": 2 } ), "jQuery.isPlainObject(object)" );
8786
assert.ok( !jQuery.isPlainObject( "foo" ), "jQuery.isPlainObject(String)" );

test/unit/core.js

Lines changed: 0 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -216,28 +216,6 @@ QUnit.test( "noConflict", function( assert ) {
216216
window[ "jQuery" ] = jQuery = $$;
217217
} );
218218

219-
QUnit.test( "trim", function( assert ) {
220-
assert.expect( 13 );
221-
222-
var nbsp = String.fromCharCode( 160 );
223-
224-
assert.equal( jQuery.trim( "hello " ), "hello", "trailing space" );
225-
assert.equal( jQuery.trim( " hello" ), "hello", "leading space" );
226-
assert.equal( jQuery.trim( " hello " ), "hello", "space on both sides" );
227-
assert.equal( jQuery.trim( " " + nbsp + "hello " + nbsp + " " ), "hello", "&nbsp;" );
228-
229-
assert.equal( jQuery.trim(), "", "Nothing in." );
230-
assert.equal( jQuery.trim( undefined ), "", "Undefined" );
231-
assert.equal( jQuery.trim( null ), "", "Null" );
232-
assert.equal( jQuery.trim( 5 ), "5", "Number" );
233-
assert.equal( jQuery.trim( false ), "false", "Boolean" );
234-
235-
assert.equal( jQuery.trim( " " ), "", "space should be trimmed" );
236-
assert.equal( jQuery.trim( "ipad\xA0" ), "ipad", "nbsp should be trimmed" );
237-
assert.equal( jQuery.trim( "\uFEFF" ), "", "zwsp should be trimmed" );
238-
assert.equal( jQuery.trim( "\uFEFF \xA0! | \uFEFF" ), "! |", "leading/trailing should be trimmed" );
239-
} );
240-
241219
QUnit.test( "isPlainObject", function( assert ) {
242220
var done = assert.async();
243221

test/unit/deprecated.js

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -600,3 +600,25 @@ QUnit[ typeof Symbol === "function" ? "test" : "skip" ]( "isNumeric(Symbol)", fu
600600
assert.equal( jQuery.isNumeric( Symbol() ), false, "Symbol" );
601601
assert.equal( jQuery.isNumeric( Object( Symbol() ) ), false, "Symbol inside an object" );
602602
} );
603+
604+
QUnit.test( "trim", function( assert ) {
605+
assert.expect( 13 );
606+
607+
var nbsp = String.fromCharCode( 160 );
608+
609+
assert.equal( jQuery.trim( "hello " ), "hello", "trailing space" );
610+
assert.equal( jQuery.trim( " hello" ), "hello", "leading space" );
611+
assert.equal( jQuery.trim( " hello " ), "hello", "space on both sides" );
612+
assert.equal( jQuery.trim( " " + nbsp + "hello " + nbsp + " " ), "hello", "&nbsp;" );
613+
614+
assert.equal( jQuery.trim(), "", "Nothing in." );
615+
assert.equal( jQuery.trim( undefined ), "", "Undefined" );
616+
assert.equal( jQuery.trim( null ), "", "Null" );
617+
assert.equal( jQuery.trim( 5 ), "5", "Number" );
618+
assert.equal( jQuery.trim( false ), "false", "Boolean" );
619+
620+
assert.equal( jQuery.trim( " " ), "", "space should be trimmed" );
621+
assert.equal( jQuery.trim( "ipad\xA0" ), "ipad", "nbsp should be trimmed" );
622+
assert.equal( jQuery.trim( "\uFEFF" ), "", "zwsp should be trimmed" );
623+
assert.equal( jQuery.trim( "\uFEFF \xA0! | \uFEFF" ), "! |", "leading/trailing should be trimmed" );
624+
} );

0 commit comments

Comments
 (0)