File tree 2 files changed +9
-4
lines changed
2 files changed +9
-4
lines changed Original file line number Diff line number Diff line change 37
37
core_rnotwhite = / \S / ,
38
38
core_rspace = / \s + / ,
39
39
40
- // IE doesn't match non-breaking spaces with \s
41
- rtrim = core_rnotwhite . test ( "\xA0" ) ? ( / ^ [ \s \xA0 ] + | [ \s \xA0 ] + $ / g ) : / ^ \s + | \s + $ / g,
40
+ // Make sure we trim BOM and NBSP (here's looking at you, Safari 5.0 and IE)
41
+ rtrim = / ^ [ \s \uFEFF \ xA0] + | [ \s \uFEFF \ xA0] + $ / g,
42
42
43
43
// A simple way to check for HTML strings
44
44
// Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
@@ -605,7 +605,7 @@ jQuery.extend({
605
605
} ,
606
606
607
607
// Use native String.trim function wherever possible
608
- trim : core_trim ?
608
+ trim : core_trim && ! core_trim . call ( "\uFEFF\xA0" ) ?
609
609
function ( text ) {
610
610
return text == null ?
611
611
"" :
Original file line number Diff line number Diff line change @@ -264,7 +264,7 @@ test("noConflict", function() {
264
264
} ) ;
265
265
266
266
test ( "trim" , function ( ) {
267
- expect ( 9 ) ;
267
+ expect ( 13 ) ;
268
268
269
269
var nbsp = String . fromCharCode ( 160 ) ;
270
270
@@ -278,6 +278,11 @@ test("trim", function() {
278
278
equal ( jQuery . trim ( null ) , "" , "Null" ) ;
279
279
equal ( jQuery . trim ( 5 ) , "5" , "Number" ) ;
280
280
equal ( jQuery . trim ( false ) , "false" , "Boolean" ) ;
281
+
282
+ equal ( jQuery . trim ( " " ) , "" , "space should be trimmed" ) ;
283
+ equal ( jQuery . trim ( "ipad\xA0" ) , "ipad" , "nbsp should be trimmed" ) ;
284
+ equal ( jQuery . trim ( "\uFEFF" ) , "" , "zwsp should be trimmed" ) ;
285
+ equal ( jQuery . trim ( "\uFEFF \xA0! | \uFEFF" ) , "! |" , "leading/trailing should be trimmed" ) ;
281
286
} ) ;
282
287
283
288
test ( "type" , function ( ) {
You can’t perform that action at this time.
0 commit comments