aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWesley Walser <wwalser@atlassian.com>2012-08-19 22:28:36 -0400
committerDave Methvin <dave.methvin@gmail.com>2012-08-19 22:39:16 -0400
commit2b5b4ebbd78ce10cbbe2a6f057feea615fc69629 (patch)
treea969980ac6f63f947ab42d103b5148a794d353a5
parent0fea007a1a4d6456a8c7d246e4f7a4e14a1ba04a (diff)
downloadjquery-2b5b4ebbd78ce10cbbe2a6f057feea615fc69629.tar.gz
jquery-2b5b4ebbd78ce10cbbe2a6f057feea615fc69629.zip
Fix #12350. Remove BOM in jQuery.trim. Close gh-897.
-rw-r--r--AUTHORS.txt3
-rw-r--r--src/core.js4
-rw-r--r--test/unit/core.js7
3 files changed, 10 insertions, 4 deletions
diff --git a/AUTHORS.txt b/AUTHORS.txt
index 01c8d76b0..e5a87c7e0 100644
--- a/AUTHORS.txt
+++ b/AUTHORS.txt
@@ -130,4 +130,5 @@ Uri Gilad <antishok@gmail.com>
Chris Faulkner <thefaulkner@gmail.com>
Elijah Manor <elijah.manor@gmail.com>
Daniel Chatfield <chatfielddaniel@googlemail.com>
-Nikita Govorov <nikita.govorov@gmail.com> \ No newline at end of file
+Nikita Govorov <nikita.govorov@gmail.com>
+Wesley Walser <wwalser@atlassian.com> \ No newline at end of file
diff --git a/src/core.js b/src/core.js
index 89e25978c..f9ee24852 100644
--- a/src/core.js
+++ b/src/core.js
@@ -37,8 +37,8 @@ var
core_rnotwhite = /\S/,
core_rspace = /\s+/,
- // IE doesn't match non-breaking spaces with \s
- rtrim = core_rnotwhite.test("\xA0") ? (/^[\s\xA0]+|[\s\xA0]+$/g) : /^\s+|\s+$/g,
+ // IE doesn't match many whitespace characters with \s
+ rtrim = core_rnotwhite.test("\xA0") ? /^[\s\xA0\uFEFF]+|[\s\xA0\uFEFF]+$/g : /^\s+|\s+$/g,
// A simple way to check for HTML strings
// Prioritize #id over <tag> to avoid XSS via location.hash (#9521)
diff --git a/test/unit/core.js b/test/unit/core.js
index 44920edcf..8b8b7afd8 100644
--- a/test/unit/core.js
+++ b/test/unit/core.js
@@ -264,7 +264,7 @@ test("noConflict", function() {
});
test("trim", function() {
- expect(9);
+ expect(13);
var nbsp = String.fromCharCode(160);
@@ -278,6 +278,11 @@ test("trim", function() {
equal( jQuery.trim( null ), "", "Null" );
equal( jQuery.trim( 5 ), "5", "Number" );
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() {