Fixes $.trim for   closes #4980
authorYehuda Katz <wycats@Yehuda-Katz.local>
Mon, 30 Nov 2009 18:21:56 +0000 (10:21 -0800)
committerYehuda Katz <wycats@Yehuda-Katz.local>
Mon, 30 Nov 2009 18:22:18 +0000 (10:22 -0800)
src/core.js
test/unit/core.js

index 3ba2a85..bdc6b2f 100644 (file)
@@ -29,7 +29,7 @@ var jQuery = function( selector, context ) {
        rnotwhite = /\S/,
 
        // Used for trimming whitespace
-       rtrim = /^\s+|\s+$/g,
+       rtrim = /(\s|\u00A0)+|(\s|\u00A0)+$/g,
 
        // Match a standalone tag
        rsingleTag = /<(\w+)\s*\/?>(?:<\/\1>)?$/,
index 4044bd8..0640cf5 100644 (file)
@@ -189,6 +189,17 @@ test("noConflict", function() {
        jQuery = $$;
 });
 
+test("trim", function() {
+  expect(4);
+
+  var nbsp = String.fromCharCode(160);
+
+  equals( jQuery.trim("hello  "), "hello", "trailing space" );
+  equals( jQuery.trim("  hello"), "hello", "leading space" );
+  equals( jQuery.trim("  hello   "), "hello", "space on both sides" );
+  equals( jQuery.trim("  " + nbsp + "hello  " + nbsp + " "), "hello", "&nbsp;" );
+});
+
 test("isFunction", function() {
        expect(19);