Commit 9e246dd7 authored by Richard Gibson's avatar Richard Gibson Committed by Dave Methvin

Fix #12350: jQuery.trim should remove BOM

parent 465959e7
...@@ -37,8 +37,8 @@ var ...@@ -37,8 +37,8 @@ var
core_rnotwhite = /\S/, core_rnotwhite = /\S/,
core_rspace = /\s+/, core_rspace = /\s+/,
// IE doesn't match non-breaking spaces with \s // Make sure we trim BOM and NBSP (here's looking at you, Safari 5.0 and IE)
rtrim = core_rnotwhite.test("\xA0") ? (/^[\s\xA0]+|[\s\xA0]+$/g) : /^\s+|\s+$/g, rtrim = /^[\s\uFEFF\xA0]+|[\s\uFEFF\xA0]+$/g,
// A simple way to check for HTML strings // A simple way to check for HTML strings
// Prioritize #id over <tag> to avoid XSS via location.hash (#9521) // Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
...@@ -605,7 +605,7 @@ jQuery.extend({ ...@@ -605,7 +605,7 @@ jQuery.extend({
}, },
// Use native String.trim function wherever possible // Use native String.trim function wherever possible
trim: core_trim ? trim: core_trim && !core_trim.call("\uFEFF\xA0") ?
function( text ) { function( text ) {
return text == null ? return text == null ?
"" : "" :
......
...@@ -264,7 +264,7 @@ test("noConflict", function() { ...@@ -264,7 +264,7 @@ test("noConflict", function() {
}); });
test("trim", function() { test("trim", function() {
expect(9); expect(13);
var nbsp = String.fromCharCode(160); var nbsp = String.fromCharCode(160);
...@@ -278,6 +278,11 @@ test("trim", function() { ...@@ -278,6 +278,11 @@ test("trim", function() {
equal( jQuery.trim( null ), "", "Null" ); equal( jQuery.trim( null ), "", "Null" );
equal( jQuery.trim( 5 ), "5", "Number" ); equal( jQuery.trim( 5 ), "5", "Number" );
equal( jQuery.trim( false ), "false", "Boolean" ); equal( jQuery.trim( false ), "false", "Boolean" );
equal( jQuery.trim(" "), "", "space should be trimmed" );
equal( jQuery.trim("ipad\xA0"), "ipad", "nbsp should be trimmed" );
equal( jQuery.trim("\uFEFF"), "", "zwsp should be trimmed" );
equal( jQuery.trim("\uFEFF \xA0! | \uFEFF"), "! |", "leading/trailing should be trimmed" );
}); });
test("type", function() { test("type", function() {
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment