[OpenLayers-Commits] r4213 - in trunk/openlayers: lib/OpenLayers tests
commits at openlayers.org
commits at openlayers.org
Tue Sep 11 07:17:00 EDT 2007
Author: crschmidt
Date: 2007-09-11 07:16:51 -0400 (Tue, 11 Sep 2007)
New Revision: 4213
Modified:
trunk/openlayers/lib/OpenLayers/BaseTypes.js
trunk/openlayers/tests/test_BaseTypes.html
Log:
Pull in upstream fix from Prototype, patch by fredj (thanks fredj!) to fix
String.prototype.trim. (Closes #961) Note that we should also be more careful
not to clobber other library prototypes. (See #962) I'm going to check this
in to fix the bug for 2.5, and we'll work on the latter in 2.6.
Modified: trunk/openlayers/lib/OpenLayers/BaseTypes.js
===================================================================
--- trunk/openlayers/lib/OpenLayers/BaseTypes.js 2007-09-11 00:22:09 UTC (rev 4212)
+++ trunk/openlayers/lib/OpenLayers/BaseTypes.js 2007-09-11 11:16:51 UTC (rev 4213)
@@ -51,18 +51,7 @@
* trailing spaces removed
*/
String.prototype.trim = function() {
-
- var b = 0;
- while(this.substr(b,1) == " ") {
- b++;
- }
-
- var e = this.length - 1;
- while(this.substr(e,1) == " ") {
- e--;
- }
-
- return this.substring(b, e+1);
+ return this.replace(/^\s+/, '').replace(/\s+$/, '');
};
/**
Modified: trunk/openlayers/tests/test_BaseTypes.html
===================================================================
--- trunk/openlayers/tests/test_BaseTypes.html 2007-09-11 00:22:09 UTC (rev 4212)
+++ trunk/openlayers/tests/test_BaseTypes.html 2007-09-11 11:16:51 UTC (rev 4213)
@@ -28,7 +28,7 @@
}
function test_03_String_trim(t) {
- t.plan(4);
+ t.plan(5);
var str = "chickenHead";
t.eq(str.trim(), "chickenHead", "string with no extra whitespace is left alone");
@@ -42,6 +42,8 @@
str = " chickenHead ";
t.eq(str.trim(), "chickenHead", "string with extra whitespace at beginning and end is trimmed correctly");
+ str = " ";
+ t.eq(str.trim(), "", "whitespace string is trimmed correctly");
}
function test_04_String_indexOf(t) {
More information about the Commits
mailing list