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

ASF GitHub Bot logged work on KNOX-3556:
----------------------------------------

                Author: ASF GitHub Bot
            Created on: 11/Nov/26 16:58
            Start Date: 11/Nov/26 16:58
    Worklog Time Spent: 10m 
      Work Description: bonampak commented on code in PR #1497:
URL: https://github.com/apache/knox/pull/1497#discussion_r4540800059


##########
gateway-provider-rewrite/src/main/java/org/apache/knox/gateway/filter/rewrite/impl/UrlRewriteUtil.java:
##########
@@ -60,13 +60,46 @@ public static UrlRewriteFilterContentDescriptor 
getRewriteFilterConfig(
 
   public static String filterJavaScript( String inputValue, 
UrlRewriteFilterContentDescriptor config,
       UrlRewriteFilterReader filterReader, 
UrlRewriteFilterPathDescriptor.Compiler<Pattern> regexCompiler ) {
+    return filterMatches( inputValue, config, filterReader, regexCompiler, 
false );
+  }
+
+  /**
+   * Rewrites every match of the applies that are configured with find, the 
rest of the input is left untouched.
+   * Applies without find have to match a whole value, they are not used here.
+   */
+  public static String filterFind( String inputValue, 
UrlRewriteFilterContentDescriptor config,
+      UrlRewriteFilterReader filterReader, 
UrlRewriteFilterPathDescriptor.Compiler<Pattern> regexCompiler ) {
+    return filterMatches( inputValue, config, filterReader, regexCompiler, 
true );
+  }
+
+  public static boolean hasFindApply( UrlRewriteFilterContentDescriptor config 
) {
+    if( config != null ) {
+      for( UrlRewriteFilterPathDescriptor selector : config.getSelectors() ) {
+        if( selector instanceof UrlRewriteFilterApplyDescriptor && 
((UrlRewriteFilterApplyDescriptor)selector).find() ) {
+          return true;
+        }
+      }
+    }
+    return false;
+  }
+
+  /*
+   * The applies are processed one after the other and every apply searches 
the output of the previous one, so an

Review Comment:
   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.





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

    Worklog Id:     (was: 1054110)
    Time Spent: 40m  (was: 0.5h)

> Rewrite: add find option to apply so URLs embedded in HTML attribute values 
> and style text can be rewritten
> -----------------------------------------------------------------------------------------------------------
>
>                 Key: KNOX-3556
>                 URL: https://issues.apache.org/jira/browse/KNOX-3556
>             Project: Apache Knox
>          Issue Type: Task
>          Components: Server
>    Affects Versions: 3.0.0
>            Reporter: Tamás Marcinkovics
>            Assignee: Tamás Marcinkovics
>            Priority: Major
>          Time Spent: 40m
>  Remaining Estimate: 0h
>
> Add find mode to rewrite {{<apply>}} for HTML attributes and text.
>  
> OpenSearch Dashboards puts its base path into the page as 
> {{{}<osd-injected-metadata 
> data="\{"basePath":"/ctx","serverBasePath":"/ctx",…}">{}}}. 
> The browser JS reads this once at startup and builds every request URL and 
> the router base from it, so the value must include the Knox prefix 
> ({{{}/gateway/<topology>/ctx{}}}).
>  
> Knox rewrites an attribute only when its whole value is a URL, so a URL 
> embedded in a JSON attribute value is left unchanged.
> Because Knox cannot rewrite inside the attribute, the backend has to be 
> configured with the gateway path and topology name. In that page only four 
> values need rewriting: basePath, serverBasePath, i18n.translationsUrl and 
> branding.assetFolderUrl. 
> About 100 font URLs in inline {{<style>}} are affected the same way.
> h4. Proposal
> Add an optional find attribute to <apply> (default false, so existing service 
> definitions are unaffected):
> {{<content type="*/html">}}
> {{<apply path="/ctx[^&"'\s\\)]*" find="true" rule="..."/>}}
> {{</content>}}
> When it is set, the HTML reader applies the regex with {{Matcher.find()}} to 
> attribute values and to {{<style>}} text. It rewrites each match through the 
> named rule and leaves the surrounding text untouched. This is the behaviour 
> the reader already has for {{<script>}} text.



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

Reply via email to