Skip to content

Apply default substitutions and SLDs consistently after loading a Mapfile - #7651

Open
geographika wants to merge 3 commits into
MapServer:mainfrom
geographika:loadmap
Open

geographika wants to merge 3 commits into
MapServer:mainfrom
geographika:loadmap

Conversation

@geographika

@geographika geographika commented Sep 19, 2026 •

Copy link
Copy Markdown
Member

This PR simplifies Mapfile loading, and handling runtime substitutions. msLoadMap currently 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 msCGILoadMap needs 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 as map2img don't have request variables so can apply default values directly. These two different paths therefore require msLoadMap to sometimes load default values directly, and sometimes wait until user supplied ones have been applied first.

To handle this msLoadMap has been made a wrapper around msLoadMapEx, which has a new bFinalize flag, that msLoadMap sets to True. This calls a new msFinalizeMap function that can call any functions required after all substitutions have been made, and a valid Mapfile is available. msFinalizeMap includes msApplyDefaultSubstitutions and msApplyStyleItemsToLayers. When bFinalize flag is set to False msFinalizeMap can be called separately once variables have been applied.

The idea of this is to avoid having to add calls to these functions after any msLoadMap calls, for example in map2img, as it would be easy to forget adding them.

Other changes:

  • As msApplyStyleItemsToLayers is now only called in this function it can be made static and renamed applyStyleItemsToLayers.

  • msLoadMapFromString also uses the new msFinalizeMap. 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 immutable block, 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.

  WEB
    VALIDATION
      'immutable' 'true'
  • msLoadMapFromString now uses const where possible (which simplifies the setting of mappath). A couple of frees were also missing in error paths, that have been added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant