Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fixes $.trim for   closes #4980

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

Why the ^ is removed from the rtrim?

@medero

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

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.
Something went wrong with that request. Please try again.