Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Fixes $.trim for   closes #4980
  • Loading branch information
Yehuda Katz authored and Yehuda Katz committed Nov 30, 2009
1 parent 84857ab commit 17955ca
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/core.js
Expand Up @@ -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>)?$/,
Expand Down
11 changes: 11 additions & 0 deletions test/unit/core.js
Expand Up @@ -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);

Expand Down

3 comments on commit 17955ca

@rkatic
Copy link
Contributor

@rkatic rkatic commented on 17955ca Nov 30, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why the ^ is removed from the rtrim?

@medero
Copy link

@medero medero commented on 17955ca Dec 18, 2009

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.