Permalink
Browse files

Fixes $.trim for   closes #4980

  • Loading branch information...
1 parent 84857ab commit 17955cacf4e8c618ca5c2b09b0d2f43df353f683 Yehuda Katz committed Nov 30, 2009
Showing with 12 additions and 1 deletion.
  1. +1 −1 src/core.js
  2. +11 −0 test/unit/core.js
View
@@ -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>)?$/,
View
@@ -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);

3 comments on commit 17955ca

Contributor

rkatic replied Nov 30, 2009

Why the ^ is removed from the rtrim?

The removal of the caret breaks this because it kills whitespace in between characters.

r = /^\s+|\s+$/g

s = ' wh at'

s = s.replace( r, '' )

Note that omission of ^ has been reverted in this commit. http://github.com/jquery/jquery/commit/abbd2f4c3c93d9550cea81ccd6d6187c115eeb56

I guess that was a typo by Yehuda.

Please sign in to comment.