[ 
https://issues.apache.org/jira/browse/WW-5823?focusedWorklogId=1051578&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1051578
 ]

ASF GitHub Bot logged work on WW-5823:
--------------------------------------

                Author: ASF GitHub Bot
            Created on: 31/Oct/26 07:55
            Start Date: 31/Oct/26 07:55
    Worklog Time Spent: 10m 
      Work Description: lukaszlenart opened a new pull request, #2077:
URL: https://github.com/apache/struts/pull/2077

   Fixes [WW-5823](https://issues.apache.org/jira/browse/WW-5823)
   
   Backport of #2076 to the 6.x line, cherry-picked from cdb638d53. The only 
difference from the original is the test setup: 6.x components have no 
`setScopedConstantProvider`, so the two calls that configured it in 
`DynamicAttributesHandlerTest` are dropped.
   
   The javatemplates plugin is a drop-in replacement for the simple theme, but 
`DynamicAttributesHandler` rendered dynamic attributes differently from 
`dynamic-attributes.ftl` in two ways:
   
   - values were stored with a raw `Attributes.put`, while every other handler 
uses `add`/`addIfExists` and the FreeMarker template writes under HTML 
auto-escaping;
   - values that `UIBean.setDynamicAttributes` had already translated were 
tested with `isExpression` again and evaluated a second time. The FreeMarker 
template evaluates only when `evaluate_dynamic_attributes` is set, which 
`radiomap.ftl` and `checkboxlist.ftl` do for their per-item rendering.
   
   ## Change
   
   - `UIBean.evaluateParams` adds a `lazyEvaluation` parameter from the 
existing `lazyEvaluation()` hook, so a template engine can tell whether the 
component left its dynamic attributes untranslated.
   - `DynamicAttributesHandler` stores every value through `Attributes.add` and 
calls `findString` only when that parameter is true. `Radio` and `CheckboxList` 
keep their per-item evaluation, since `RadioHandler` and `CheckboxListHandler` 
push each item before calling `start`.
   
   ## Compatibility
   
   Under the java engine a dynamic attribute value is now HTML-escaped once, as 
it already is under the FreeMarker themes. A value that resolves to text in the 
percent-brace form is rendered literally instead of being evaluated, matching 
the FreeMarker output. This also covers the FreeMarker tag syntax, where 
`copyAttributes` hands dynamic attributes to the component untranslated. Lazily 
evaluated components are unchanged.
   
   ## Tests
   
   `DynamicAttributesHandlerTest` covers an escaped resolved value next to the 
escaped standard `title` attribute, an escaped literal value, a resolved value 
in the percent-brace form rendered literally on `textfield`, and `radiomap` 
still evaluating per item. The javatemplates suite passes on this branch with 
core rebuilt.
   
   🤖 Generated with [Claude Code](https://claude.com/claude-code)
   




Issue Time Tracking
-------------------

    Worklog Id:     (was: 1051578)
    Time Spent: 50m  (was: 40m)

> Javatemplates plugin renders dynamic attributes differently from the simple 
> theme: values are not HTML-escaped and are evaluated a second time
> ----------------------------------------------------------------------------------------------------------------------------------------------
>
>                 Key: WW-5823
>                 URL: https://issues.apache.org/jira/browse/WW-5823
>             Project: Struts 2
>          Issue Type: Bug
>          Components: Plugin - Java Templates
>            Reporter: Lukasz Lenart
>            Assignee: Lukasz Lenart
>            Priority: Major
>             Fix For: 6.13.0, 7.5.0
>
>          Time Spent: 50m
>  Remaining Estimate: 0h
>
> The javatemplates plugin is documented as a drop-in replacement for the 
> simple theme. {{DynamicAttributesHandler.processDynamicAttributes}} differs 
> from the FreeMarker {{dynamic-attributes.ftl}} in two ways.
> # Dynamic attribute values are stored with {{Attributes.put}}. Every other 
> handler in the plugin goes through {{Attributes.add}} or {{addIfExists}}, 
> which apply {{escapeHtml4}}, and the FreeMarker template writes the value 
> under the configuration's HTML auto-escaping. {{XHTMLTagSerializer.start}} 
> then writes the stored value between double quotes as it is.
> # {{UIBean.setDynamicAttributes}} already translates the percent-brace 
> expressions for every component that is not lazily evaluated. The handler 
> tests the resolved value with {{ComponentUtils.isExpression}} again and calls 
> {{findString}} on it, so a value that resolves to text in the percent-brace 
> form is evaluated a second time. The FreeMarker template evaluates only when 
> {{evaluate_dynamic_attributes}} is set, which {{radiomap.ftl}} and 
> {{checkboxlist.ftl}} do because {{Radio}} and {{CheckboxList}} return 
> {{lazyEvaluation() == true}} and render their dynamic attributes per list 
> item.
> h2. Observed
> With {{struts.ui.templateSuffix=java}} and the {{hint}} property bound from 
> the request:
> {code}<s:textfield name="q" data-hint="%{hint}"/>
> hint = a "b" c      java: data-hint="a "b" c"          ftl: data-hint="a 
> &quot;b&quot; c"
> hint = %{1+1}       java: data-hint="2"                ftl: data-hint="%{1+1}"
> {code}
> The standard attributes of the same tag ({{value}}, {{title}}) render 
> identically under both engines. Every tag wired through 
> {{DynamicAttributesHandler}} in {{SimpleTheme}} behaves the same way.
> h2. Proposed change
> * Store dynamic attribute values through {{Attributes.add}}, in line with the 
> other handlers and the FreeMarker templates.
> * Evaluate a dynamic attribute in the handler only when the component is 
> lazily evaluated. {{UIBean}} already knows this through {{lazyEvaluation()}}; 
> expose it as a component parameter so the plugin can read it. {{Radio}} and 
> {{CheckboxList}} keep their per-item evaluation in the handler chain, where 
> {{RadioHandler}} and {{CheckboxListHandler}} push each item before calling 
> {{start}}.
> h2. Compatibility
> Under the java engine, a dynamic attribute value is now HTML-escaped once, as 
> it already is under the FreeMarker themes; a value that already contains 
> entities is escaped again, matching the FreeMarker output. A value that 
> resolves to text in the percent-brace form is rendered literally instead of 
> being evaluated, matching the FreeMarker output. Lazily evaluated components 
> are unchanged.
> h2. Tests
> * A dynamic attribute whose resolved value contains a double quote renders 
> escaped under the java engine.
> * A dynamic attribute whose resolved value is in the percent-brace form 
> renders literally on a non-lazy component.
> * A dynamic attribute on {{Radio}} is still evaluated per item in the handler.
> * The existing dynamic-attribute rendering tests keep passing for every tag 
> in {{SimpleTheme}}.
> Reported by Claude and Ada Logics.



--
This message was sent by Atlassian Jira
(v10.3.26#10030026)

Reply via email to