[ 
https://issues.apache.org/jira/browse/WW-3571?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=18127771#comment-18127771
 ] 

Lukasz Lenart commented on WW-3571:
-----------------------------------

Revisited on current {{main}}: the behaviour is unchanged. An {{<s:a>}} with no 
{{href}} and no URL attributes still renders an {{href}} pointing at the 
current action URL.

*Deleting the {{else}} branch is not an option.* That branch is what builds 
URLs for {{<s:a action="..." namespace="..." method="...">}}. Removing it 
breaks most of {{AnchorTagTest}}.

*Planned change for 8.0.0:* build the URL only when the page author set at 
least one URL attribute: {{value}}, {{action}}, {{namespace}}, {{method}}, 
{{includeParams}}, {{anchor}}, {{scheme}}, or a nested {{<s:param>}}. When none 
is set, render no {{href}}.
* Linking to the current page explicitly keeps working, e.g. {{<s:a 
includeParams="get">}} or {{<s:a>}} with only {{<s:param>}} children. This 
matches the {{url}} tag's documented behaviour.
* The check has to look at the attributes written on the tag, not at the 
{{UrlProvider}} state. The {{struts.url.includeParams}} constant is injected 
into the same field, so {{includeParams}} always looks set there.
* A fully bare {{<s:a>}} stops linking to the current page. Anyone who relied 
on that can add {{includeParams="none"}} or an explicit {{href}}.

This was moved to 8.0.0 because it changes rendered output for existing pages. 
Until then, {{href=""}} renders an empty {{href}} rather than omitting it, so 
it is not a full workaround.

Related: WW-5782 (an explicit {{href}} silently drops nested {{<s:param>}} 
tags).

> Anchor tag is providing a default value for href attribute when it should not
> -----------------------------------------------------------------------------
>
>                 Key: WW-3571
>                 URL: https://issues.apache.org/jira/browse/WW-3571
>             Project: Struts 2
>          Issue Type: Bug
>    Affects Versions: 2.1.8, 2.2.1.1
>            Reporter: James House
>            Assignee: Maurizio Cucchiara
>            Priority: Major
>             Fix For: 8.0.0
>
>
> The Anchor tag is providing a default value for href attribute when it should 
> not.
> Previous versions of Struts2 did not do this, and in fact the documentation 
> for the tag also says there is no default value.
> However it is placing a default value of the current URL, rather than leaving 
> the href attribute off altogether.  (it is legal per HTML to not have an href 
> attribute, and in fact we had existing code that was trying to purposely 
> leave it off, but now instead of being left off, it is rendered with the 
> current URL).
> I believe the problem was introduced with the changes related to WW-3037.   
> This block of code (from Anchor.java) precisely:
> {code}
>     @Override
>     protected void evaluateExtraParams() {
>         super.evaluateExtraParams();
>         if (href != null)
>             addParameter("href", 
> ensureAttributeSafelyNotEscaped(findString(href)));
>         else {
>             //no href, build it from URL attributes
>             StringWriter sw = new StringWriter();
>             urlRenderer.beforeRenderUrl(urlProvider);
>             urlRenderer.renderUrl(sw, urlProvider);
>             String builtHref = sw.toString();
>             if (StringUtils.isNotEmpty(builtHref))
>                 addParameter("href", 
> ensureAttributeSafelyNotEscaped(builtHref));
>         }
>     }
> {code}
> To preserve documented and previous functionality of allowing href to not be 
> rendered in the tag, the entire "else" block should be removed (of course 
> that significantly negates WW-3037 - which apparently didn't think about the 
> fact that it is legit to not have an href for the anchor).



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to