]> source.dussan.org Git - jquery.git/commitdiff
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 3ba2a859d9682d85a0b499d60804ff0c81469dab..bdc6b2f5ee298fb47d87484f2d58e6d16d6759a9 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 4044bd85683dca98d9cfddc005bdf505a94750b3..0640cf5ce24052c6c1137c1d6d41999c1dff04b1 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);