Skip to content

Commit

Permalink
Shorter RegExp for trim polyfill. Fixes #617
Browse files Browse the repository at this point in the history
  • Loading branch information
madrobby committed Mar 3, 2013
1 parent 2efb3fb commit 3771d17
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 1 deletion.
2 changes: 1 addition & 1 deletion src/polyfill.js
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test/polyfill.html
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ <h1>Compatibility tests</h1>
// 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
Expand Down

0 comments on commit 3771d17

Please sign in to comment.