Ticket #961 (closed bug: fixed)
String.prototype.trim failed to trim a whitespace string
| Reported by: | fredj | Owned by: | |
|---|---|---|---|
| Priority: | major | Milestone: | 2.5 Release |
| Component: | general | Version: | SVN |
| Keywords: | Cc: | ||
| State: |
Description
As reported by John Cole on the dev mailing list:
I’ve run into an issue with OL 2.4 (branch HEAD) and Microsoft Ajax.Net.
In BaseTypes.js, the following function:
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);
};
Is failing because e is going negative and goes into an endless loop. The
string being fed (from an Ajax.Net call) is simply two spaces (“ “).
It appears that Ajax.Net is also prototyping a trim function onto String,
and commenting out the one in BaseTypes.js gets everything working again.
How do you detect that a function has already been prototyped on to a class
so OL doesn’t have to do it?
Here is a test_String.html that confirms the issue.
<html>
<head>
<script src="../../lib/OpenLayers.js"></script>
<script type="text/javascript"><!--
function test_01_Trim (t) {
t.plan( 1 );
var s;
s = " test ".trim();
t.eq( s, "test", "string.trim worked correctly");
}
function test_01a_Trim (t) {
t.plan( 1 );
var s;
s = " ".trim();
t.eq( s, "", "string.trim worked correctly");
}
// -->
</script>
</head>
<body></body>
</html>
Thanks,
John
Attachments
Change History
Note: See
TracTickets for help on using
tickets.

