You are viewing a plain text version of this content. The canonical link for it is here.
Posted to issues@struts.apache.org by "Lukasz Lenart (Jira)" <ji...@apache.org> on 2026/10/12 17:58:00 UTC

[jira] [Resolved] (WW-5767) Apply value substitution to scoped-constant values, as for constant

     [ https://issues.apache.org/jira/browse/WW-5767?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Lukasz Lenart resolved WW-5767.
-------------------------------
    Resolution: Fixed

> 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
>
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> 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)