LayerManager / layman

Publishing geospatial vector data online
GNU General Public License v3.0
10 stars 3 forks source link

Sanitize invalid XML element names (attribute names) #902

Open jmacura opened 1 year ago

jmacura commented 1 year ago

When a layer which is being published contains attributes formed as URLs (which is common in the RDF world), the published layer may produce an invalid XML response.

e.g. for this GetFeatureInfo request on WMS layer: https://hub4everybody.com/geoserver/franta_wms/ows?SERVICE=WMS&VERSION=1.3.0&REQUEST=GetFeatureInfo&FORMAT=image/png&TRANSPARENT=true&QUERY_LAYERS=spoi_italy&LAYERS=spoi_italy&INFO_FORMAT=application/vnd.ogc.gml&feature_count=1&I=6&J=144&WIDTH=256&HEIGHT=256&CRS=EPSG:3857&STYLES=&BBOX=1023950.4309082218,5695017.229415342,1024103.3049647921,5695170.103471912

the returned FeatureCollection is

<?xml version="1.0" encoding="UTF-8"?><wfs:FeatureCollection xmlns="http://www.opengis.net/wfs" xmlns:wfs="http://www.opengis.net/wfs" xmlns:franta_wms="http://franta_wms" xmlns:gml="http://www.opengis.net/gml" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.opengis.net/wfs https://hub4everybody.com/geoserver/schemas/wfs/1.0.0/WFS-basic.xsd http://franta_wms https://hub4everybody.com/geoserver/franta_wms/wfs?service=WFS&amp;version=1.0.0&amp;request=DescribeFeatureType&amp;typeName=franta_wms%3Aspoi_italy">
  <gml:boundedBy>
    <gml:Box srsName="http://www.opengis.net/gml/srs/epsg.xml#3857">
      <gml:coordinates xmlns:gml="http://www.opengis.net/gml" decimal="." cs="," ts=" ">1024018.8676,5693426.8733 1024018.8676,5693426.8733</gml:coordinates>
    </gml:Box>
  </gml:boundedBy>
  <gml:featureMember>
    <franta_wms:spoi_italy fid="spoi_italy.16816">
      <gml:boundedBy>
        <gml:Box srsName="http://www.opengis.net/gml/srs/epsg.xml#3857">
          <gml:coordinates xmlns:gml="http://www.opengis.net/gml" decimal="." cs="," ts=" ">1024018.8676,5693426.8733 1024018.8676,5693426.8733</gml:coordinates>
        </gml:Box>
      </gml:boundedBy>
      <franta_wms:id>http://www.sdi4apps.eu/poi/#OSM_2516079384</franta_wms:id>
      <franta_wms:http://www.w3.org/1999/02/22_rdf_syntax_ns_type>http://gis.zcu.cz/SPOI/Ontology#restaurant</franta_wms:http://www.w3.org/1999/02/22_rdf_syntax_ns_type>
      <franta_wms:wkb_geometry>
        <gml:Point srsName="http://www.opengis.net/gml/srs/epsg.xml#3857">
          <gml:coordinates xmlns:gml="http://www.opengis.net/gml" decimal="." cs="," ts=" ">1024018.8676,5693426.8733</gml:coordinates>
        </gml:Point>
      </franta_wms:wkb_geometry>
    </franta_wms:spoi_italy>
  </gml:featureMember>
</wfs:FeatureCollection>

where <franta_wms:http://www.w3.org/1999/02/22_rdf_syntax_ns_type>...</franta_wms:http://www.w3.org/1999/02/22_rdf_syntax_ns_type> is not a valid XML node name.

see https://github.com/hslayers/hslayers-ng/issues/4036

A correct response shall actually include <rdf:type>http://gis.zcu.cz/SPOI/Ontology#restaurant</rdf:type> instead of <franta_wms:http://www.w3.org/1999/02/22_rdf_syntax_ns_type>http://gis.zcu.cz/SPOI/Ontology#restaurant</franta_wms:http://www.w3.org/1999/02/22_rdf_syntax_ns_type>. With xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#" in the XML header (or in the wfs:FeatureCollection node).

jirik commented 1 year ago

@jmacura Thanks for reporting. Could you please add also sample input file (GeoJSON or SHP)?

jirik commented 1 year ago

Could be useful: https://docs.geoserver.org/stable/en/user/community/features-templating/index.html

jmacura commented 1 year ago

Provided the problematic layer is this one: https://hub4everybody.com/micka/record/basic/m-967bcafb-d0e0-4f91-9c28-f984cba7fde8 , I guess the original source was this GeoJSON: all-pois-italy.zip

Also, I can now confirm that even WFS GetFeature request contains the invalid XML tags.