Skip to content
Browse files

Shorter RegExp for trim polyfill. Fixes #617

  • Loading branch information...
1 parent 4c0c581 commit c4b45c517e85e19a490ace44ddd4482bdea9e557 @madrobby madrobby committed with lopper Mar 2, 2013
Showing with 2 additions and 1 deletion.
  1. +1 −1 src/polyfill.js
  2. +1 −0 test/polyfill.html
View
2 src/polyfill.js
@@ -4,7 +4,7 @@
;(function(undefined){
if (String.prototype.trim === undefined) // fix for iOS 3.2
- String.prototype.trim = function(){ return this.replace(/^\s+/, '').replace(/\s+$/, '') }
+ String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/g, '') }
// For iOS 3.x
// from https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/reduce
View
1 test/polyfill.html
@@ -23,6 +23,7 @@
// test to see if we augment String.prototype.trim if not supported natively
testTrim: function(t){
t.assertEqual("blah", " blah ".trim())
+ t.assertEqual("bl \n ah", " bl \n ah ".trim())
},
// test to see if we augment Array.prototype.reduceif not supported natively

0 comments on commit c4b45c5

Please sign in to comment.
Something went wrong with that request. Please try again.