Skip to content

Commit add01bf

Browse files
committed
Add additional tests and only get projection when using WMS
1 parent 08c793b commit add01bf

5 files changed

Lines changed: 112 additions & 9 deletions

File tree

Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>MapServer Simple Viewer</title>
7+
<link rel="stylesheet" href="//mapserver.org/lib/10.5.0/ol-mapserver.css">
8+
<link rel="shortcut icon" type="image/x-icon" href="//mapserver.org/_static/mapserver.ico" />
9+
<style>
10+
#map {
11+
position: absolute;
12+
top: 0;
13+
left: 0;
14+
width: 100%;
15+
height: 100%;
16+
}
17+
</style>
18+
</head>
19+
<body>
20+
<div id="map"></div>
21+
<script src="//mapserver.org/lib/10.5.0/ol-mapserver.js"></script>
22+
<script>
23+
const mslayer = new ol.layer.Image({
24+
extent: [-180.000000, -180.000000, 180.000000, 180.000000],
25+
source: new ol.source.Image({
26+
loader: ol.source.mapserver.createLoader({
27+
url: 'http://localhost/?map=msautotest/misc/openlayers.map&',
28+
params: {
29+
'layers': 'world-polys world-lines quo&quot;tes&#39;'
30+
}
31+
})
32+
})
33+
});
34+
const map = new ol.Map({
35+
layers: [mslayer],
36+
target: 'map',
37+
view: new ol.View()
38+
});
39+
map.getView().fit([-180.000000, -180.000000, 180.000000, 180.000000], { size: map.getSize() });
40+
</script>
41+
</body>
42+
</html>
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
6+
<title>MapServer Simple Viewer</title>
7+
<link rel="stylesheet" href="//mapserver.org/lib/10.5.0/ol-mapserver.css">
8+
<link rel="shortcut icon" type="image/x-icon" href="//mapserver.org/_static/mapserver.ico" />
9+
<style>
10+
#map {
11+
position: absolute;
12+
top: 0;
13+
left: 0;
14+
width: 100%;
15+
height: 100%;
16+
}
17+
</style>
18+
</head>
19+
<body>
20+
<div id="map"></div>
21+
<script src="//mapserver.org/lib/10.5.0/ol-mapserver.js"></script>
22+
<script>
23+
const mslayer = new ol.layer.Image({
24+
extent: [-180.000000, -180.000000, 180.000000, 180.000000],
25+
source: new ol.source.Image({
26+
loader: ol.source.mapserver.createLoader({
27+
url: 'http://localhost/?map=msautotest/misc/openlayers.map&',
28+
params: {
29+
'layers': 'x&lt;/script&gt;&lt;img src=x onerror=alert(document.domain)&gt;&lt;script&gt;'
30+
}
31+
})
32+
})
33+
});
34+
const map = new ol.Map({
35+
layers: [mslayer],
36+
target: 'map',
37+
view: new ol.View()
38+
});
39+
map.getView().fit([-180.000000, -180.000000, 180.000000, 180.000000], { size: map.getSize() });
40+
</script>
41+
</body>
42+
</html>

msautotest/misc/expected/wms.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
loader: ol.source.wms.createLoader({
2929
url: 'http://localhost/?map=msautotest/misc/openlayers.map&',
3030
params: {
31-
LAYERS: 'world-polys,world-lines',
31+
LAYERS: 'world-polys,world-lines,quo&quot;tes&#39;',
3232
VERSION: '1.3.0',
3333
FORMAT: 'image/png'
3434
},

msautotest/misc/openlayers.map

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# Test OpenLayers HTML template output through CGI and WMS
22

33
# RUN_PARMS: browse.html [MAPSERV] QUERY_STRING="map=[MAPFILE]&layers=world-polys world-lines&mode=browse&template=openlayers" > [RESULT_DEMIME]
4-
# RUN_PARMS: wms.html [MAPSERV] QUERY_STRING="map=[MAPFILE]&REQUEST=GetMap&SERVICE=WMS&VERSION=1.3.0&FORMAT=application/openlayers&STYLES=&TRANSPARENT=false&LAYERS=world-polys,world-lines&WIDTH=956&HEIGHT=705&CRS=EPSG:4326&BBOX=-180,-90,180,90" > [RESULT_DEMIME]
4+
# RUN_PARMS: browse_all.html [MAPSERV] QUERY_STRING="map=[MAPFILE]&layers=all&mode=browse&template=openlayers" > [RESULT_DEMIME]
5+
# RUN_PARMS: browse_invalid.html [MAPSERV] QUERY_STRING="map=[MAPFILE]&layers=x%3C/script%3E%3Cimg%20src%3Dx%20onerror%3Dalert(document.domain)%3E%3Cscript%3E&mode=browse&template=openlayers&SRS=x%3C/script%3E%3Cimg%20src%3Dx%20onerror%3Dalert(document.domain)%3E%3Cscript%3E" > [RESULT_DEMIME]
6+
# RUN_PARMS: wms.html [MAPSERV] QUERY_STRING="map=[MAPFILE]&REQUEST=GetMap&SERVICE=WMS&VERSION=1.3.0&FORMAT=application/openlayers&STYLES=&TRANSPARENT=false&LAYERS=world-polys,world-lines,quo%5C%22tes%27&WIDTH=956&HEIGHT=705&CRS=EPSG:4326&BBOX=-180,-90,180,90" > [RESULT_DEMIME]
57
# RUN_PARMS: wms_projected.html [MAPSERV] QUERY_STRING="map=[MAPFILE]&REQUEST=GetMap&SERVICE=WMS&VERSION=1.3.0&FORMAT=application/openlayers&STYLES=&TRANSPARENT=false&LAYERS=world-polys,world-lines&WIDTH=956&HEIGHT=705&CRS=EPSG:3857&BBOX=-20037508.34,-20048966.1,20037508.34,20048966.1" > [RESULT_DEMIME]
68
# RUN_PARMS: wms_projected_extra.html [MAPSERV] QUERY_STRING="map=[MAPFILE]&REQUEST=GetMap&SERVICE=WMS&VERSION=1.3.0&FORMAT=application/openlayers&STYLES=&TRANSPARENT=false&LAYERS=world-polys,world-lines&WIDTH=956&HEIGHT=705&CRS=EPSG:3395&BBOX=-20037508.34,-15496570.74,20037508.34,18764656.23" > [RESULT_DEMIME]
79
# RUN_PARMS: wms_invalid_parameter1.html [MAPSERV] QUERY_STRING="map=[MAPFILE]&REQUEST=GetMap&SERVICE=WMS&VERSION=1.1.1&FORMAT=application/openlayers&STYLES=&TRANSPARENT=false&LAYERS=world-polys,world-lines&WIDTH=956&HEIGHT=705&CRS=x%3C/script%3E%3Cimg%20src%3Dx%20onerror%3Dalert(document.domain)%3E%3Cscript%3E&BBOX=-20037508.34,-15496570.74,20037508.34,18764656.23" > [RESULT_DEMIME]
@@ -62,4 +64,17 @@ MAP
6264
END
6365
END
6466

67+
LAYER
68+
NAME "quo\"tes'"
69+
TYPE LINE
70+
STATUS OFF
71+
DATA "data/testlines.shp"
72+
CLASS
73+
STYLE
74+
WIDTH 0.5
75+
COLOR 255 0 0
76+
END
77+
END
78+
END
79+
6580
END

src/maptemplate.c

Lines changed: 11 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -5017,14 +5017,17 @@ int msReturnOpenLayersPage(mapservObj *mapserv) {
50175017

50185018
/* Determine whether this is a 1.3.0 request.
50195019
* CRS is used for VERSION 1.3.0, SRS for earlier versions. */
5020-
const int use_crs = (version != NULL && strcmp(version, "1.3.0") >= 0);
5021-
const char *proj_param = use_crs ? "CRS" : "SRS";
50225020

5023-
/* get the correct projection parameter */
5024-
for (i = 0; i < mapserv->request->NumParams; i++) {
5025-
if (strcasecmp(mapserv->request->ParamNames[i], proj_param) == 0) {
5026-
projection = mapserv->request->ParamValues[i];
5027-
break;
5021+
if (mapserv->Mode != BROWSE) {
5022+
const int use_crs = (version != NULL && strcmp(version, "1.3.0") >= 0);
5023+
const char *proj_param = use_crs ? "CRS" : "SRS";
5024+
5025+
/* get the correct projection parameter */
5026+
for (i = 0; i < mapserv->request->NumParams; i++) {
5027+
if (strcasecmp(mapserv->request->ParamNames[i], proj_param) == 0) {
5028+
projection = msEncodeHTMLEntities(mapserv->request->ParamValues[i]);
5029+
break;
5030+
}
50285031
}
50295032
}
50305033

@@ -5067,6 +5070,7 @@ int msReturnOpenLayersPage(mapservObj *mapserv) {
50675070
msIO_fwrite(buffer, strlen(buffer), 1, stdout);
50685071
free(layer);
50695072
free(buffer);
5073+
free(projection);
50705074

50715075
return MS_SUCCESS;
50725076
}

0 commit comments

Comments
 (0)