FIx #9510: EsriJSON readGeometry should not mutate input
This commit is contained in:
@@ -256,10 +256,10 @@ function readGeometry(object, opt_options) {
|
|||||||
const rings = convertRings(esriJSONPolygon.rings, layout);
|
const rings = convertRings(esriJSONPolygon.rings, layout);
|
||||||
if (rings.length === 1) {
|
if (rings.length === 1) {
|
||||||
type = GeometryType.POLYGON;
|
type = GeometryType.POLYGON;
|
||||||
object['rings'] = rings[0];
|
object = Object.assign({}, object, {['rings']: rings[0]});
|
||||||
} else {
|
} else {
|
||||||
type = GeometryType.MULTI_POLYGON;
|
type = GeometryType.MULTI_POLYGON;
|
||||||
object['rings'] = rings;
|
object = Object.assign({}, object, {['rings']: rings});
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
const geometryReader = GEOMETRY_READERS[type];
|
const geometryReader = GEOMETRY_READERS[type];
|
||||||
|
|||||||
@@ -712,6 +712,23 @@ describe('ol.format.EsriJSON', function() {
|
|||||||
]);
|
]);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
it('should not mutate input', function() {
|
||||||
|
const input = {
|
||||||
|
rings: [
|
||||||
|
[[0, 1, 0, 1], [1, 4, 0, 1], [4, 3, 0, 1], [3, 0, 0, 1]],
|
||||||
|
[[2, 2, 0, 1], [3, 2, 0, 1], [3, 3, 0, 1], [2, 3, 0, 1]],
|
||||||
|
[[10, 1, 0, 1], [11, 5, 0, 1], [14, 3, 0, 1], [13, 0, 0, 1]]
|
||||||
|
],
|
||||||
|
hasZ: true,
|
||||||
|
hasM: true
|
||||||
|
};
|
||||||
|
const str = JSON.stringify(input);
|
||||||
|
const obj = format.readGeometry(input);
|
||||||
|
|
||||||
|
expect(obj).to.be.a(MultiPolygon);
|
||||||
|
expect(str).to.eql(JSON.stringify(input));
|
||||||
|
});
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
describe('#readProjection', function() {
|
describe('#readProjection', function() {
|
||||||
|
|||||||
Reference in New Issue
Block a user