[
https://issues.apache.org/jira/browse/WW-5821?focusedWorklogId=1056482&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-1056482
]
ASF GitHub Bot logged work on WW-5821:
--------------------------------------
Author: ASF GitHub Bot
Created on: 22/Nov/26 09:04
Start Date: 22/Nov/26 09:04
Worklog Time Spent: 10m
Work Description: lukaszlenart opened a new pull request, #2151:
URL: https://github.com/apache/struts/pull/2151
Fixes [WW-5821](https://issues.apache.org/jira/browse/WW-5821)
Follow-up to #2043, covering the three items left open in its last review.
## Changes
- **Unrestricted `HttpMethodAware` action is covered.** A new test sends
`PROPFIND` to an `HttpMethodAware` action with no annotation and no
`http-method`. The invocation proceeds with a 200, and `setMethod(null)`
overwrites the value set beforehand. The test fails if the interceptor skips
`setMethod` for an unknown verb.
- **One matching rule.** `HttpMethod.parse` now builds on `parseOrNull` and
throws `IllegalArgumentException` for an unknown method.
`HttpMethodInterceptor#isAllowed` resolves the request method with
`parseOrNull` and checks `Set.contains`, so an unknown verb is never allowed by
construction.
- **Unused import removed.** `HttpMethodInterceptorTest` extends the JUnit 3
`TestCase`, so the static `Assert.assertNull` import was never used.
## Behaviour
`isAllowed` returns the same result as before for every request method,
including lower and mixed case, `null` and unknown verbs.
`parse` is only called for the `http-method` attribute in XML configuration.
It now matches with `equalsIgnoreCase` instead of `toUpperCase(Locale.ROOT)`,
so a value whose upper-case form changes length, such as one containing the `st`
ligature, now fails at startup instead of mapping to `POST`. Invalid values
still surface as a `ConfigurationException`.
## Testing
```
./mvnw -pl core -DskipAssembly
-Dtest='HttpMethod*Test,XmlConfigurationProvider*Test' test
```
All pass, including `HttpMethodInterceptorTest` (43 tests).
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Issue Time Tracking
-------------------
Worklog Id: (was: 1056482)
Time Spent: 0.5h (was: 20m)
> HttpMethodInterceptor raises IllegalArgumentException for an unknown HTTP
> method on an HttpMethodAware action
> -------------------------------------------------------------------------------------------------------------
>
> Key: WW-5821
> URL: https://issues.apache.org/jira/browse/WW-5821
> Project: Struts 2
> Issue Type: Bug
> Components: Core Interceptors
> Reporter: Lukasz Lenart
> Priority: Major
> Fix For: 7.6.0
>
> Time Spent: 0.5h
> Remaining Estimate: 0h
>
> When an action implements {{HttpMethodAware}}, {{HttpMethodInterceptor}}
> converts the request method with {{HttpMethod.parse()}}, which calls
> {{valueOf()}} with no fallback. A request method outside the enum constants,
> such as {{PROPFIND}}, {{MKCOL}} or {{REPORT}}, raises
> {{IllegalArgumentException}} before the allowed-method checks run, so the
> client gets a 500 instead of the configured rejection.
> h2. Steps to reproduce
> # Define an action that implements {{HttpMethodAware}} and restricts methods,
> for example with {{@AllowedHttpMethod(POST)}} or {{http-method="POST"}}.
> # Send {{PROPFIND}} to that action.
> h2. Expected
> The request is rejected like any other disallowed method: the bad-request
> result, or {{405 Method Not Allowed}} with an {{Allow}} header when no such
> result is mapped.
> h2. Actual
> {code}java.lang.IllegalArgumentException: No enum constant
> org.apache.struts2.interceptor.httpmethod.HttpMethod.PROPFIND
> at java.base/java.lang.Enum.valueOf(Enum.java:273)
> at
> org.apache.struts2.interceptor.httpmethod.HttpMethod.parse(HttpMethod.java:40)
> {code}
> h2. Proposed change
> Add {{HttpMethod.parseOrNull()}}, a case-insensitive lookup that returns
> {{null}} for an unknown method. The interceptor passes that value to
> {{HttpMethodAware.setMethod()}}, documented as {{null}} for an unknown
> method, and falls through to the existing allowed-method check. {{parse()}}
> switches to {{Locale.ROOT}}, and {{XmlDocConfigurationProvider}} uses it for
> the {{http-method}} attribute.
> Pull request: [apache/struts#2043|https://github.com/apache/struts/pull/2043]
--
This message was sent by Atlassian Jira
(v10.3.26#10030026)