Skip to content

Commit 2b5b4eb

Browse files
Wesley Walserdmethvin
Wesley Walser
authored andcommitted
Fix #12350. Remove BOM in jQuery.trim. Close jquerygh-897.
1 parent 0fea007 commit 2b5b4eb

File tree

3 files changed

+10
-4
lines changed

3 files changed

+10
-4
lines changed

AUTHORS.txt

+2-1
Original file line numberDiff line numberDiff line change
@@ -130,4 +130,5 @@ Uri Gilad <antishok@gmail.com>
130130
Chris Faulkner <thefaulkner@gmail.com>
131131
Elijah Manor <elijah.manor@gmail.com>
132132
Daniel Chatfield <chatfielddaniel@googlemail.com>
133-
Nikita Govorov <nikita.govorov@gmail.com>
133+
Nikita Govorov <nikita.govorov@gmail.com>
134+
Wesley Walser <wwalser@atlassian.com>

src/core.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -37,8 +37,8 @@ var
3737
core_rnotwhite = /\S/,
3838
core_rspace = /\s+/,
3939

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+
// IE doesn't match many whitespace characters with \s
41+
rtrim = core_rnotwhite.test("\xA0") ? /^[\s\xA0\uFEFF]+|[\s\xA0\uFEFF]+$/g : /^\s+|\s+$/g,
4242

4343
// A simple way to check for HTML strings
4444
// Prioritize #id over <tag> to avoid XSS via location.hash (#9521)

test/unit/core.js

+6-1
Original file line numberDiff line numberDiff line change
@@ -264,7 +264,7 @@ test("noConflict", function() {
264264
});
265265

266266
test("trim", function() {
267-
expect(9);
267+
expect(13);
268268

269269
var nbsp = String.fromCharCode(160);
270270

@@ -278,6 +278,11 @@ test("trim", function() {
278278
equal( jQuery.trim( null ), "", "Null" );
279279
equal( jQuery.trim( 5 ), "5", "Number" );
280280
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" );
281286
});
282287

283288
test("type", function() {

0 commit comments

Comments
 (0)