Croway opened a new pull request, #30871:
URL: https://github.com/apache/camel/pull/30871
# Description
`AiResourceUriTemplate` (from CAMEL-26354) matches each template variable
with a greedy repetition of a group that contains an alternation:
```
(?:[A-Za-z0-9._~!$&'()*+,;=:@-]|%[0-9A-Fa-f]{2})+
```
`java.util.regex` repeats such a group recursively, one stack frame per
repetition. A variable value of a few thousand characters therefore throws
`StackOverflowError` from `match()`, for example about 5,000 characters on a
default thread stack. In an MCP server, a template read with such a URI failed
with a server error before the route was called.
This PR makes the quantifier possessive (`)++`), so the engine repeats the
group without recursion. Matching is unchanged:
- A variable always occupies a whole path segment, followed by `/` or by the
end of the URI.
- `%` is not in the single-character class, so a value can be split into
tokens in only one way.
- The matcher therefore never needs to backtrack into a variable.
Tests, in `AiResourceUriTemplateTest`:
- `matchesLongVariableValues`: 100,000-character and 50,000
percent-encoded-octet values match in a two-variable template and are returned
verbatim.
- `rejectsLongVariableValuesWithAnInvalidTail`: a long value followed by
`?`, an incomplete escape `%4`, a trailing `/` or an extra segment is refused.
- The existing cases are unchanged. The camel-ai-resource,
camel-mcp-server-api and camel-mcp-server tests pass.
Main only: the URI template support is not in a released version, so no
backport and no upgrade-guide entry.
_Claude Code on behalf of Federico Mariani_
# Target
- [x] I checked that the commit is targeting the correct branch (Camel 4
uses the `main` branch)
# Tracking
- [x] If this is a large change, bug fix, or code improvement, I checked
there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for
the change (usually before you start working on it).
# Apache Camel coding standards and style
- [x] I checked that each commit in the pull request has a meaningful
subject line and body.
- [ ] I have run `mvn clean install -DskipTests` locally from root folder
and I have committed all auto-generated changes.
# AI-assisted contributions
- [ ] If this PR includes AI-generated code, commits have proper
co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR
description identifies the AI tool used.
--
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
To unsubscribe, e-mail: [email protected]
For queries about this service, please contact Infrastructure at:
[email protected]