Skip to content

Commit 8fedf99

Browse files
author
Tom Fili
authoredNov 30, 2017
Merge pull request #5972 from JeremyMarzano-ISPA/master
Remove Duplicate Namespace Declarations
2 parents fe85699 + 5f22786 commit 8fedf99

File tree

6 files changed

+61
-0
lines changed

6 files changed

+61
-0
lines changed
 

‎CHANGES.md

+1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ Change Log
1313
* Fixed a bug where glTF models with animations of different lengths would cause an error. [#5694](https://github.com/AnalyticalGraphicsInc/cesium/issues/5694)
1414
* Added a `clampAnimations` parameter to `Model` and `Entity.model`. Setting this to `false` allows different length animations to loop asynchronously over the duration of the longest animation.
1515
* Fixed `Invalid asm.js: Invalid member of stdlib` console error by recompiling crunch.js with latest emscripten toolchain. [#5847](https://github.com/AnalyticalGraphicsInc/cesium/issues/5847)
16+
* Added function that removes duplicate namespace declarations while loading a KML or a KMZ. [#5972](https://github.com/AnalyticalGraphicsInc/cesium/pull/5972)
1617
* Added `file:` scheme compatibility to `joinUrls`. [#5989](https://github.com/AnalyticalGraphicsInc/cesium/pull/5989)
1718
* Added a Reverse Geocoder [Sandcastle example](https://cesiumjs.org/Cesium/Apps/Sandcastle/?src=Reverse%20Geocoder.html&label=Showcases). [#5976](https://github.com/AnalyticalGraphicsInc/cesium/pull/5976)
1819
* Added ability to support touch event in Imagery Layers Split Sandcastle example. [#5948](https://github.com/AnalyticalGraphicsInc/cesium/pull/5948)

‎CONTRIBUTORS.md

+1
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
9999
* [Joshua Bernstein](https://github.com/jbernstein/)
100100
* [Natanael Rivera](https://github.com/nrivera-Novetta/)
101101
* [Justin Burr](https://github.com/jburr-nc/)
102+
* [Jeremy Marzano](https://github.com/JeremyMarzano-ISPA/)
102103

103104
## [Individual CLA](Documentation/Contributors/CLAs/individual-cla-agi-v1.0.txt)
104105
* [Victor Berchet](https://github.com/vicb)

‎Source/DataSources/KmlDataSource.js

+25
Original file line numberDiff line numberDiff line change
@@ -282,9 +282,31 @@ define([
282282
return text;
283283
}
284284

285+
function removeDuplicateNamespaces(text) {
286+
var index = text.indexOf('xmlns:');
287+
var endDeclaration = text.indexOf('>', index);
288+
var namespace, startIndex, endIndex;
289+
290+
while ((index !== -1) && (index < endDeclaration)) {
291+
namespace = text.slice(index, text.indexOf('\"', index));
292+
startIndex = index;
293+
index = text.indexOf(namespace, index + 1);
294+
if (index !== -1) {
295+
endIndex = text.indexOf('\"', (text.indexOf('\"', index) + 1));
296+
text = text.slice(0, index -1) + text.slice(endIndex + 1, text.length);
297+
index = text.indexOf('xmlns:', startIndex - 1);
298+
} else {
299+
index = text.indexOf('xmlns:', startIndex + 1);
300+
}
301+
}
302+
303+
return text;
304+
}
305+
285306
function loadXmlFromZip(reader, entry, uriResolver, deferred) {
286307
entry.getData(new zip.TextWriter(), function(text) {
287308
text = insertNamespaces(text);
309+
text = removeDuplicateNamespaces(text);
288310
uriResolver.kml = parser.parseFromString(text, 'application/xml');
289311
deferred.resolve();
290312
});
@@ -2369,6 +2391,9 @@ define([
23692391
//Insert missing namespaces
23702392
text = insertNamespaces(text);
23712393

2394+
//Remove Duplicate Namespaces
2395+
text = removeDuplicateNamespaces(text);
2396+
23722397
//IE raises an exception
23732398
var kml;
23742399
var error;

‎Specs/Data/KML/duplicateNamespace.kml

+18
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<kml xmlns="http://www.opengis.net/kml/2.2" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:gx="http://www.google.com/kml/ext/2.2" xmlns:gx="http://www.google.com/kml/ext/2.2">
3+
<Document xsi:schemaLocation="http://www.opengis.net/kml/2.2 http://schemas.opengis.net/kml/2.2.0/ogckml22.xsd http://www.google.com/kml/ext/2.2 http://code.google.com/apis/kml/schema/kml22gx.xsd">
4+
<Placemark>
5+
<Style>
6+
<IconStyle>
7+
<Icon>
8+
<href>image.png</href>
9+
</Icon>
10+
</IconStyle>
11+
</Style>
12+
<description><![CDATA[image.png <a href="./image.png">image.png</a><img src="image.png"/>]]></description>
13+
<Point>
14+
<coordinates>1,2,3</coordinates>
15+
</Point>
16+
</Placemark>
17+
</Document>
18+
</kml>

‎Specs/Data/KML/duplicateNamespace.kmz

1 KB
Binary file not shown.

‎Specs/DataSources/KmlDataSourceSpec.js

+16
Original file line numberDiff line numberDiff line change
@@ -260,6 +260,22 @@ defineSuite([
260260
});
261261
});
262262

263+
it('load deletes duplicate namespace declaration in kml', function() {
264+
var datasource = new KmlDataSource(options);
265+
return datasource.load('Data/KML/duplicateNamespace.kml').then(function(source) {
266+
expect(source).toBe(datasource);
267+
expect(source.entities.values.length).toEqual(1);
268+
});
269+
});
270+
271+
it('load deletes duplicate namespace declaration in kmz', function() {
272+
var dataSource = new KmlDataSource(options);
273+
return dataSource.load('Data/KML/duplicateNamespace.kmz').then(function(source) {
274+
expect(source).toBe(dataSource);
275+
expect(source.entities.values.length).toEqual(1);
276+
});
277+
});
278+
263279
it('load rejects nonexistent URL', function() {
264280
return KmlDataSource.load('test.invalid', options).otherwise(function(e) {
265281
expect(e).toBeInstanceOf(RequestErrorEvent);

0 commit comments

Comments
 (0)