Apply default substitutions and SLDs consistently after loading a Mapfile - #7651
Open
geographika wants to merge 3 commits into
Open
geographika wants to merge 3 commits into
geographika wants to merge 3 commits into
Conversation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This PR simplifies Mapfile loading, and handling runtime substitutions.
msLoadMapcurrently leaves it to each caller to apply default substitutions and SLD replacement, which is easy to forget and is done inconsistently.The main issue is
msCGILoadMapneeds to load the Mapfile, then apply any runtime variables from the request, and finally apply default values and load any SLD files.msLoadMap, used in apps such asmap2imgdon't have request variables so can apply default values directly. These two different paths therefore requiremsLoadMapto sometimes load default values directly, and sometimes wait until user supplied ones have been applied first.To handle this
msLoadMaphas been made a wrapper aroundmsLoadMapEx, which has a newbFinalizeflag, thatmsLoadMapsets toTrue. This calls a newmsFinalizeMapfunction that can call any functions required after all substitutions have been made, and a valid Mapfile is available.msFinalizeMapincludesmsApplyDefaultSubstitutionsandmsApplyStyleItemsToLayers. WhenbFinalizeflag is set toFalsemsFinalizeMapcan be called separately once variables have been applied.The idea of this is to avoid having to add calls to these functions after any
msLoadMapcalls, for example inmap2img, as it would be easy to forget adding them.Other changes:
As
msApplyStyleItemsToLayersis now only called in this function it can be made static and renamedapplyStyleItemsToLayers.msLoadMapFromStringalso uses the newmsFinalizeMap. This changes functionality for MapScript which previously required default values to be manually applied. The Python test suite has been updated accordingly.New tests have been added for the
immutableblock, which is currently untested and undocumented. It is a flag that means any runtime values in a request are ignored. Default values however should still be applied (which was not the case - so it is fixed by this PR). Applying default values avoids invalid Mapfiles in this case, and there is no security risk as they are part of the Mapfile.msLoadMapFromStringnow usesconstwhere possible (which simplifies the setting ofmappath). A couple of frees were also missing in error paths, that have been added.