Skip to content

Commit

Permalink
#7678 (#1184) - use strict param
Browse files Browse the repository at this point in the history
  • Loading branch information
lgoltz committed Nov 22, 2021
1 parent 13d6b88 commit f320dde
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,8 @@ public class GetMap extends RequestBase {

private static final Logger LOG = getLogger( GetMap.class );

private static final boolean PARSE_LAX = false;

private static GeometryFactory fac = new GeometryFactory();

private ICRS crs;
Expand Down Expand Up @@ -143,12 +145,13 @@ public class GetMap extends RequestBase {
* @param exts
* @throws OWSException
*/
public GetMap( Map<String, String> map, Version version, MapOptionsMaps exts ) throws OWSException {
public GetMap( Map<String, String> map, Version version, MapOptionsMaps exts, boolean parseStrict )
throws OWSException {
if ( version.equals( VERSION_111 ) ) {
parse111( map, exts );
}
if ( version.equals( VERSION_130 ) ) {
parse130( map, exts );
parse130( map, exts, parseStrict );
}
parameterMap.putAll( map );
try {
Expand All @@ -164,7 +167,6 @@ public GetMap( Map<String, String> map, Version version, MapOptionsMaps exts ) t
}

/**
* @param service
* @param layers
* @param styles
* @param width
Expand Down Expand Up @@ -299,7 +301,7 @@ private void parse111( Map<String, String> map, MapOptionsMaps exts )

bbox = fac.createEnvelope( new double[] { vals[0], vals[1] }, new double[] { vals[2], vals[3] }, crs );

handleCommon( map, exts );
handleCommon( map, exts, PARSE_LAX );
}

static LinkedList<StyleRef> handleKVPStyles( String ss, int numLayers )
Expand Down Expand Up @@ -384,7 +386,7 @@ private void handlePixelSize( Map<String, String> map ) {
}
}

private void handleCommon( Map<String, String> map, MapOptionsMaps exts )
private void handleCommon( Map<String, String> map, MapOptionsMaps exts, boolean parseStrict )
throws OWSException {
String ls = map.get( "LAYERS" );
String sld = map.get( "SLD" );
Expand Down Expand Up @@ -440,9 +442,11 @@ private void handleCommon( Map<String, String> map, MapOptionsMaps exts )
OWSException.INVALID_PARAMETER_VALUE );
}
String t = map.get( "TRANSPARENT" );
if ( t != null && !t.equalsIgnoreCase( "true" ) && !t.equalsIgnoreCase( "false" ) ) {

if ( parseStrict && ( t != null && !t.equalsIgnoreCase( "true" ) && !t.equalsIgnoreCase( "false" ) ) ) {
throw new OWSException(
"The TRANSPARENT parameter value is not valid (was " + t + "), expected is TRUE or FALSE.",
"The TRANSPARENT parameter value is not valid (was " + t
+ "), expected is TRUE or FALSE.",
OWSException.INVALID_PARAMETER_VALUE );
}
transparent = t != null && t.equalsIgnoreCase( "true" );
Expand Down Expand Up @@ -608,7 +612,7 @@ public static List<?> parseDimensionValues( String value, String name )
return null;
}

private void parse130( Map<String, String> map, MapOptionsMaps exts )
private void parse130( Map<String, String> map, MapOptionsMaps exts, boolean parseStrict )
throws OWSException {
String c = map.get( "CRS" );
if ( c == null || c.trim().isEmpty() ) {
Expand Down Expand Up @@ -644,7 +648,7 @@ private void parse130( Map<String, String> map, MapOptionsMaps exts )
bbox = getCRSAndEnvelope130( c, vals );
crs = bbox.getCoordinateSystem();

handleCommon( map, exts );
handleCommon( map, exts, parseStrict );
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void testTransparent_True()
throws Exception {
Map<String, String> kvp = createRequest(
"BBOX=228152.00000000%2C5690412.00000000%2C493382.00000000%2C5939023.00000000&CRS=EPSG%3A25833&FORMAT=image%2Fpng&HEIGHT=500&LAYERS=EF.EnvironmentalMonitoringProgrammes&REQUEST=GetMap&SERVICE=WMS&STYLES=EF.EnvironmentalMonitoringProgrammes.Default.Point&TRANSPARENT=tRue&VERSION=1.3.0&WIDTH=500" );
GetMap getMap = new GetMap( kvp, Version.parseVersion( "1.3.0" ), null );
GetMap getMap = new GetMap( kvp, Version.parseVersion( "1.3.0" ), null, true );
assertTrue( getMap.getTransparent() );
}

Expand All @@ -30,7 +30,7 @@ public void testTransparent_False()
throws Exception {
Map<String, String> kvp = createRequest(
"BBOX=228152.00000000%2C5690412.00000000%2C493382.00000000%2C5939023.00000000&CRS=EPSG%3A25833&FORMAT=image%2Fpng&HEIGHT=500&LAYERS=EF.EnvironmentalMonitoringProgrammes&REQUEST=GetMap&SERVICE=WMS&STYLES=EF.EnvironmentalMonitoringProgrammes.Default.Point&TRANSPARENT=fAlSe&VERSION=1.3.0&WIDTH=500" );
GetMap getMap = new GetMap( kvp, Version.parseVersion( "1.3.0" ), null );
GetMap getMap = new GetMap( kvp, Version.parseVersion( "1.3.0" ), null, true );
assertFalse( getMap.getTransparent() );
}

Expand All @@ -39,7 +39,16 @@ public void testTransparent_Invalid()
throws Exception {
Map<String, String> kvp = createRequest(
"BBOX=228152.00000000%2C5690412.00000000%2C493382.00000000%2C5939023.00000000&CRS=EPSG%3A25833&FORMAT=image%2Fpng&HEIGHT=500&LAYERS=EF.EnvironmentalMonitoringProgrammes&REQUEST=GetMap&SERVICE=WMS&STYLES=EF.EnvironmentalMonitoringProgrammes.Default.Point&TRANSPARENT=zzzz&VERSION=1.3.0&WIDTH=500" );
new GetMap( kvp, Version.parseVersion( "1.3.0" ), null );
new GetMap( kvp, Version.parseVersion( "1.3.0" ), null, true );
}

@Test
public void testTransparent_Invalid_ParseLax()
throws Exception {
Map<String, String> kvp = createRequest(
"BBOX=228152.00000000%2C5690412.00000000%2C493382.00000000%2C5939023.00000000&CRS=EPSG%3A25833&FORMAT=image%2Fpng&HEIGHT=500&LAYERS=EF.EnvironmentalMonitoringProgrammes&REQUEST=GetMap&SERVICE=WMS&STYLES=EF.EnvironmentalMonitoringProgrammes.Default.Point&TRANSPARENT=zzzz&VERSION=1.3.0&WIDTH=500" );
GetMap getMap = new GetMap( kvp, Version.parseVersion( "1.3.0" ), null, false );
assertFalse( getMap.getTransparent() );
}

private Map<String, String> createRequest( String queryParams )
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -521,7 +521,8 @@ private static void addHeaders( HttpResponseBuffer response, LinkedList<String>
protected void getMap( Map<String, String> map, HttpResponseBuffer response, Version version )
throws OWSException, IOException, MissingDimensionValue, InvalidDimensionValue {
org.deegree.protocol.wms.ops.GetMap gm2 = new org.deegree.protocol.wms.ops.GetMap( map, version,
service.getExtensions() );
service.getExtensions(),
isStrict );

doGetMap( map, response, version, gm2 );
}
Expand Down

0 comments on commit f320dde

Please sign in to comment.