polyline: Improved decoding loops to be more robust
This commit is contained in:
+22
-14
@@ -213,19 +213,22 @@ ol.parser.polyline.encodeUnsignedIntegers = function(numbers) {
|
|||||||
ol.parser.polyline.decodeUnsignedIntegers = function(encoded) {
|
ol.parser.polyline.decodeUnsignedIntegers = function(encoded) {
|
||||||
var numbers = new Array();
|
var numbers = new Array();
|
||||||
|
|
||||||
|
var current = 0;
|
||||||
|
var shift = 0;
|
||||||
|
|
||||||
var encodedLength = encoded.length;
|
var encodedLength = encoded.length;
|
||||||
for (var i = 0; i < encodedLength;) {
|
for (var i = 0; i < encodedLength; ++i) {
|
||||||
var result = 0;
|
var b = encoded.charCodeAt(i) - 63;
|
||||||
var shift = 0;
|
|
||||||
|
|
||||||
var b;
|
current |= (b & 0x1f) << shift;
|
||||||
do {
|
|
||||||
b = encoded.charCodeAt(i++) - 63;
|
if (b < 0x20) {
|
||||||
result |= (b & 0x1f) << shift;
|
numbers.push(current);
|
||||||
|
current = 0;
|
||||||
|
shift = 0;
|
||||||
|
} else {
|
||||||
shift += 5;
|
shift += 5;
|
||||||
} while (b >= 0x20);
|
}
|
||||||
|
|
||||||
numbers.push(result);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return numbers;
|
return numbers;
|
||||||
@@ -316,12 +319,17 @@ ol.parser.polyline.decodeUnsignedInteger = function(encoded) {
|
|||||||
var result = 0;
|
var result = 0;
|
||||||
var shift = 0;
|
var shift = 0;
|
||||||
|
|
||||||
var b, i = 0;
|
var encodedLength = encoded.length;
|
||||||
do {
|
for (var i = 0; i < encodedLength; ++i) {
|
||||||
b = encoded.charCodeAt(i++) - 63;
|
var b = encoded.charCodeAt(i) - 63;
|
||||||
|
|
||||||
result |= (b & 0x1f) << shift;
|
result |= (b & 0x1f) << shift;
|
||||||
|
|
||||||
|
if (b < 0x20)
|
||||||
|
break;
|
||||||
|
|
||||||
shift += 5;
|
shift += 5;
|
||||||
} while (b >= 0x20);
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
};
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user