WW-5437 Swap order of sysStrSubstitutor and envStrSubstitutor in substitute method #977
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.
According to the documentation at https://struts.apache.org/core-developers/constant-configuration it should be possible to use both system and environment variables in the constants section. Currently environment variables are ignored if a default value is defined.
The sysStrSubstitutor has a less specific prefix which also includes and replaces those, which should be passed to the envStrSubstitutor later.
Given
<constant name="struts.devMode" value="${env.STRUTS_DEV_MODE:false}"/>
and System.getenv('STRUTS_DEV_MODE') is "true"
The old code:
The sysStrSubstitutor checks, if there is a system property with the key "env.STRUTS_DEV_MODE" which is unset. It then replaces the expression with its default. substituted is "false" now. Afterwards the envStrSubstitutor doesn't find any expression to substitute, because the string is "false".
The new code:
The envStrSubstitutor only accepts expressions prefixed with "env.", so it ignores any unprefixed (aka system-) variables. If not set, substituted remains unchanged and is replaced by the system variable or eventually the default in the next step.
I'm not sure if this all is right and understandable but for me, the new behavior is what I've exprected after reading the docs and telling my DevOps team how to enable the devMode for my test-container :)
Closes WW-5437