Skip to content

Commit

Permalink
Merge pull request #5972 from JeremyMarzano-ISPA/master
Browse files Browse the repository at this point in the history
Remove Duplicate Namespace Declarations
  • Loading branch information
Tom Fili authored Nov 30, 2017
2 parents fe85699 + 5f22786 commit 8fedf99
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 0 deletions.
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ Change Log
* Fixed a bug where glTF models with animations of different lengths would cause an error. [#5694](https://github.com/AnalyticalGraphicsInc/cesium/issues/5694)
* 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.
* 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)
* Added function that removes duplicate namespace declarations while loading a KML or a KMZ. [#5972](https://github.com/AnalyticalGraphicsInc/cesium/pull/5972)
* Added `file:` scheme compatibility to `joinUrls`. [#5989](https://github.com/AnalyticalGraphicsInc/cesium/pull/5989)
* 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)
* Added ability to support touch event in Imagery Layers Split Sandcastle example. [#5948](https://github.com/AnalyticalGraphicsInc/cesium/pull/5948)
Expand Down
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Original file line number Diff line number Diff line change
Expand Up @@ -99,6 +99,7 @@ See [CONTRIBUTING.md](CONTRIBUTING.md) for details on how to contribute to Cesiu
* [Joshua Bernstein](https://github.com/jbernstein/)
* [Natanael Rivera](https://github.com/nrivera-Novetta/)
* [Justin Burr](https://github.com/jburr-nc/)
* [Jeremy Marzano](https://github.com/JeremyMarzano-ISPA/)

## [Individual CLA](Documentation/Contributors/CLAs/individual-cla-agi-v1.0.txt)
* [Victor Berchet](https://github.com/vicb)
Expand Down
25 changes: 25 additions & 0 deletions Source/DataSources/KmlDataSource.js
Original file line number Diff line number Diff line change
Expand Up @@ -282,9 +282,31 @@ define([
return text;
}

function removeDuplicateNamespaces(text) {
var index = text.indexOf('xmlns:');
var endDeclaration = text.indexOf('>', index);
var namespace, startIndex, endIndex;

while ((index !== -1) && (index < endDeclaration)) {
namespace = text.slice(index, text.indexOf('\"', index));
startIndex = index;
index = text.indexOf(namespace, index + 1);
if (index !== -1) {
endIndex = text.indexOf('\"', (text.indexOf('\"', index) + 1));
text = text.slice(0, index -1) + text.slice(endIndex + 1, text.length);
index = text.indexOf('xmlns:', startIndex - 1);
} else {
index = text.indexOf('xmlns:', startIndex + 1);
}
}

return text;
}

function loadXmlFromZip(reader, entry, uriResolver, deferred) {
entry.getData(new zip.TextWriter(), function(text) {
text = insertNamespaces(text);
text = removeDuplicateNamespaces(text);
uriResolver.kml = parser.parseFromString(text, 'application/xml');
deferred.resolve();
});
Expand Down Expand Up @@ -2369,6 +2391,9 @@ define([
//Insert missing namespaces
text = insertNamespaces(text);

//Remove Duplicate Namespaces
text = removeDuplicateNamespaces(text);

//IE raises an exception
var kml;
var error;
Expand Down
18 changes: 18 additions & 0 deletions Specs/Data/KML/duplicateNamespace.kml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?xml version="1.0" encoding="UTF-8"?>
<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">
<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">
<Placemark>
<Style>
<IconStyle>
<Icon>
<href>image.png</href>
</Icon>
</IconStyle>
</Style>
<description><![CDATA[image.png <a href="./image.png">image.png</a><img src="image.png"/>]]></description>
<Point>
<coordinates>1,2,3</coordinates>
</Point>
</Placemark>
</Document>
</kml>
Binary file added Specs/Data/KML/duplicateNamespace.kmz
Binary file not shown.
16 changes: 16 additions & 0 deletions Specs/DataSources/KmlDataSourceSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,22 @@ defineSuite([
});
});

it('load deletes duplicate namespace declaration in kml', function() {
var datasource = new KmlDataSource(options);
return datasource.load('Data/KML/duplicateNamespace.kml').then(function(source) {
expect(source).toBe(datasource);
expect(source.entities.values.length).toEqual(1);
});
});

it('load deletes duplicate namespace declaration in kmz', function() {
var dataSource = new KmlDataSource(options);
return dataSource.load('Data/KML/duplicateNamespace.kmz').then(function(source) {
expect(source).toBe(dataSource);
expect(source.entities.values.length).toEqual(1);
});
});

it('load rejects nonexistent URL', function() {
return KmlDataSource.load('test.invalid', options).otherwise(function(e) {
expect(e).toBeInstanceOf(RequestErrorEvent);
Expand Down

0 comments on commit 8fedf99

Please sign in to comment.