Skip to content

KNOX-3556: Rewrite: add find option to apply so URLs embedded in HTML attribute values and style text can be rewritten - #1497

Merged
smolnar82 merged 5 commits into
apache:masterfrom
bonampak:KNOX-3556
Nov 11, 2026
Merged

smolnar82 merged 5 commits into
apache:masterfrom
bonampak:KNOX-3556

Conversation

@bonampak

@bonampak bonampak commented Nov 9, 2026 •

Copy link
Copy Markdown
Contributor

KNOX-3556 - Add find mode to rewrite <apply> for HTML attributes and text.

What changes were proposed in this pull request?

Add find mode to rewrite <apply> for HTML attributes and text.
Updated dev guide.

How was this patch tested?

  • Unit tests.
  • find defaults to false and no existing service definition uses it. UrlRewriteFilterApplyDescriptor interface was modified with default methods so legacy code does not break.
  • mvn clean verify succeeded

@bonampak bonampak self-assigned this Nov 9, 2026
@github-actions

github-actions Bot commented Nov 9, 2026 •

Copy link
Copy Markdown

Test Results

  5 files    5 suites   1m 38s ⏱️
198 tests 196 ✅ 2 💤 0 ❌
239 runs  237 ✅ 2 💤 0 ❌

Results for commit 83c6076.

♻️ This comment has been updated with latest results.

@smolnar82 smolnar82 left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, the approach looks good.

One naming nit: find reflects the Matcher.find() vs matches() implementation detail, but to a service-definition author find="true" doesn't really say "rewrite every occurrence within the value instead of requiring a whole-value match".

Something like match="partial" (default "whole") or scope="substring" would be more self-explanatory, and an enum also leaves room for other modes later. Since no service definition uses it yet, now would be the cheapest time to rename.

}

/*
* The applies are processed one after the other and every apply searches the output of the previous one, so an

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The applies are chained: each find apply searches the output of the previous one, so with multiple find applies a value can get rewritten twice (e.g. /app -> /gateway/topo/app, then a second find apply matching /gateway/... rewrites it again). That was already the case for <script> content, but with this change it applies to every HTML attribute and text node. Could the dev guide state that find paths must be disjoint/anchored (or should a value be rewritten by at most one find apply)?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I went with the dev guide option.

Applies are chained on purpose, the same as for JS content, so there's one behavior to document.

I've added a note to the dev guide that several partial applies are chained and their paths must be disjoint/anchored, plus a complete example with a rule and an anchored path.
If a real need for several overlapping partial applies comes up, "rewrite each part at most once" can be added then; it would only change configs that already rewrite twice.

return this;
}

public void setFind( boolean find ) {

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

find is populated via digester's SetPropertiesRule / BeanUtils, which silently converts an invalid value to false (verified: ConvertUtils.convert("ture", boolean.class) returns false with beanutils 1.11.0). So a typo like find="ture" quietly disables the rewrite with no error or log. Not a blocker, but it may be worth validating the attribute (only true/false accepted) or at least logging a warning when loading the rules.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

With the rename to match="partial|whole", the attribute is an enum parsed via Enum.valueOf, so an invalid value like match="parttial" now fails the rules load instead of silently falling back (same as an invalid flow). This is covered by testLoadApplyInvalidMatch.

A misspelled attribute name is still ignored, but that's Digester's SetPropertiesRule default for every rewrite.xml attribute, so I'd leave it out of this ticket.

The test revealed that the digester is not cleared after failure, so if a subsequent load() invocations could fail. I'd keep that as a separate ticket.

bonampak and others added 2 commits November 11, 2026 17:33
find came from Matcher.find() vs matches(). To a service definition
author it doesn't say what it does. Use match="partial" instead, with
match="whole" as the default. An enum also leaves room for other
modes later. No service definition uses the attribute yet.

- Add a UrlRewriteFilterApplyMatch { WHOLE, PARTIAL } enum, like UrlRewriteStepFlow, in place of find(). It is parsed case-insensitively like flow, and the exporter writes it back without a special case.

- Rename the related methods, tests and docs.

Co-Authored-By: Claude <noreply@anthropic.com>
Several match="partial" applies are applied one after the other, so
their paths have to be disjoint. Add an example with a rule and a path
anchored on both sides.

Co-Authored-By: Claude <noreply@anthropic.com>
@smolnar82
smolnar82 merged commit fa89d6a into apache:master Nov 11, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants