Skip to content
Permalink
Browse files

Fixes $.trim for   closes #4980

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

@rkatic

This comment has been minimized.

Copy link
Contributor

rkatic replied Nov 30, 2009

Why the ^ is removed from the rtrim?

@medero

This comment has been minimized.

Copy link

medero replied Dec 18, 2009

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, '' )

@neerajdotname

This comment has been minimized.

Copy link

neerajdotname replied Dec 18, 2009

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.
You can’t perform that action at this time.