botaohu / earth-api-samples

Automatically exported from code.google.com/p/earth-api-samples
0 stars 0 forks source link

Content scrubbing malforming kml feature names in loaded kml #945

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
The getName() method of KmlFeatures seems to be using the content scrubbing 
functionality as used for the plugin balloon content.

This issues occurs even when the name element simply contains brackets "()". 
The scrubbing string is appended to the name and the brackets are converted to 
their HTML codes. This is possibly true for other strings as well.

What steps will reproduce the problem?
1. Load a Kml file that has <name> elements that contains brackets. i.e. 
<name>test (123)</name>

2. Call getName() on a feature that has a <name> element as above 

3. The name returned will be 
<!-- Content-type: mhtml-die-die-die --> test&#040;123&#041

What is the expected output or behavior? What do you see instead?

The expected output of getName() would be the content of the name element.
i.e. test (123)

Which plugin version are you using?
7.1.1.1580

Which browsers and operating systems are affected?
OS: Windows XP, Windows 7 and Windows 8 
Browser: IE 8,9 and 10, Chrome 26.0.1410 

Please provide any additional information (code snippets/links) below.

The workaround I have been using is to clean the returned value from getName()

var function cleanName(name) {
  var result = name.replace(/\s*<!--\s*Content-type: mhtml-die-die-die\s*-->/, ''));
  result = result.replace(/\s*&#040;/, '('));
  result = result.replace(/\s*&#041;/, ')'));
  return result ;
}

var name = cleanName(feature.getName());

Original issue reported on code.google.com by fraser.c...@gmail.com on 22 May 2013 at 7:50

GoogleCodeExporter commented 9 years ago
Excellent find, thanks. 
Not sure about the javascript though. 
I removed the leading var:
from  
var function cleanName(name) {
to
function cleanName(name) {

and replaced the double closing brackets with a single closing bracket in each 
of the replace lines:
e.g. from:
result = result.replace(/\s*(/, '('));
to
result = result.replace(/\s*(/, '(');  

Original comment by gpsanima...@gmail.com on 22 Nov 2013 at 1:22