[
https://issues.apache.org/jira/browse/WW-5767?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
]
Lukasz Lenart updated WW-5767:
------------------------------
Fix Version/s: 7.5.0
> Apply value substitution to scoped-constant values, as for constant
> -------------------------------------------------------------------
>
> Key: WW-5767
> URL: https://issues.apache.org/jira/browse/WW-5767
> Project: Struts 2
> Issue Type: Improvement
> Components: XML Configuration
> Reporter: Lukasz Lenart
> Priority: Major
> Fix For: 7.5.0
>
>
> h2. Background
> [WW-3476|https://issues.apache.org/jira/browse/WW-3476] adds the
> {{scoped-constant}} element to {{package}} (struts-7.5.dtd). Its values are
> stored exactly as written:
> {{XmlDocConfigurationProvider.loadScopedConstants}} passes the raw {{value}}
> attribute to {{PackageConfig.Builder.addScopedConstant}}.
> The global {{constant}} element is different. Since 2.5.6 its value goes
> through the injected {{ValueSubstitutor}} (default {{EnvsValueSubstitutor}})
> in {{XmlDocConfigurationProvider}} before it is registered, which resolves
> environment variables and system properties once, at load time:
> {code:xml}<constant name="some.constant" value="${env.SOME_VALUE}"/>
> {code}
> The same expression in a scoped constant is kept literally:
> {code:xml}<package name="admin" extends="struts-default">
> <scoped-constant name="some.scopable.constant" value="${env.SOME_VALUE}"/>
> </package>
> {code}
> h2. Why this looks unintended
> The WW-3476 design ruled out per-request expression evaluation of scoped
> constants, because their values are static. Value substitution is something
> else: it runs once while the configuration loads and produces a static
> string, exactly like for {{constant}}. Leaving it out makes the two elements
> behave differently for no design reason.
> h2. Proposal
> * In {{XmlDocConfigurationProvider.loadScopedConstants}}, run the value
> through {{valueSubstitutor}} when one is set, the same way global constants
> are handled.
> * No change to {{PackageConfig}}, the startup validation or
> {{ScopedConstantProvider}}. They receive the substituted string.
> h2. Tests
> * {{XmlConfigurationProviderPackagesTest}}: a fixture with a scoped constant
> whose value refers to a system property set by the test resolves to the
> property's value.
> * A literal value without an expression is kept unchanged.
> h2. Documentation
> The struts-site page {{core-developers/package-configuration.md}} currently
> says value substitution is not supported for scoped constants
> ([apache/struts-site#351|https://github.com/apache/struts-site/pull/351]).
> Update that sentence once this lands.
--
This message was sent by Atlassian Jira
(v8.20.10#820010)