[
https://issues.apache.org/jira/browse/WW-5767?focusedWorklogId=1046993&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1046993
]
ASF GitHub Bot logged work on WW-5767:
--------------------------------------
Author: ASF GitHub Bot
Created on: 12/Oct/26 12:13
Start Date: 12/Oct/26 12:13
Worklog Time Spent: 10m
Work Description: lukaszlenart opened a new pull request, #2007:
URL: https://github.com/apache/struts/pull/2007
Fixes [WW-5767](https://issues.apache.org/jira/browse/WW-5767)
## Summary
`<scoped-constant>` values (added in WW-3476) are now run through the
injected `ValueSubstitutor` when the configuration loads, the same way
`<constant>` values have been since 2.5.6. `${env.NAME}` and
`${system.property}` now resolve instead of being kept as literal text.
```xml
<package name="admin" extends="struts-default">
<scoped-constant name="some.scopable.constant"
value="${env.SOME_VALUE}"/>
</package>
```
`registerConstant` and `loadScopedConstants` now call one private helper,
`substituteValue`, so the two elements can't drift apart. Substitution still
runs once, at load time, and produces a static string. This is not the
per-request evaluation that WW-3476 ruled out. `PackageConfig`, the startup
validation and `ScopedConstantProvider` are unchanged.
## Tests
`ScopedConstantsSubstitutionTest` (new, JUnit 4) with a new fixture,
`struts-scoped-constants-substitution.xml`:
- A scoped constant set to `${ww5767.value}` resolves to the system property
the test sets, then clears.
- A literal value is kept as written.
The test loads `struts-default.xml` in Dispatcher order. `loadPackages()`
gets its `ValueSubstitutor` from the main container, which in production comes
from `struts-beans.xml`. The ticket suggested
`XmlConfigurationProviderPackagesTest`, but its `ConfigurationTestBase`
container registers no substitutor, so a test there could not see the change.
Before the fix, the test failed with `but was: "${ww5767.value}"`. The
existing `XmlConfigurationProviderEnvsSubstitutionTest` still passes after the
refactor. The full `core` suite passes: 3447 tests, 0 failures.
## Follow-up
The struts-site page `core-developers/package-configuration.md` says value
substitution is not supported for scoped constants (apache/struts-site#351).
That sentence needs updating once this is merged.
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Issue Time Tracking
-------------------
Worklog Id: (was: 1046993)
Remaining Estimate: 0h
Time Spent: 10m
> 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: 10m
> 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)