diff --git a/src/ol/format/EsriJSON.js b/src/ol/format/EsriJSON.js index d8006b9066..2a15c14368 100644 --- a/src/ol/format/EsriJSON.js +++ b/src/ol/format/EsriJSON.js @@ -256,10 +256,10 @@ function readGeometry(object, opt_options) { const rings = convertRings(esriJSONPolygon.rings, layout); if (rings.length === 1) { type = GeometryType.POLYGON; - object['rings'] = rings[0]; + object = Object.assign({}, object, {['rings']: rings[0]}); } else { type = GeometryType.MULTI_POLYGON; - object['rings'] = rings; + object = Object.assign({}, object, {['rings']: rings}); } } const geometryReader = GEOMETRY_READERS[type]; diff --git a/test/spec/ol/format/esrijson.test.js b/test/spec/ol/format/esrijson.test.js index 4f92375755..7513708d6d 100644 --- a/test/spec/ol/format/esrijson.test.js +++ b/test/spec/ol/format/esrijson.test.js @@ -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() {