[ https://issues.apache.org/jira/browse/KNOX-2931?focusedWorklogId=869110&page=com.atlassian.jira.plugin.system.issuetabpanels:worklog-tabpanel#worklog-869110 ]
ASF GitHub Bot logged work on KNOX-2931: ---------------------------------------- Author: ASF GitHub Bot Created on: 04/Jul/23 13:12 Start Date: 04/Jul/23 13:12 Worklog Time Spent: 10m Work Description: zeroflag opened a new pull request, #769: URL: https://github.com/apache/knox/pull/769 ## What changes were proposed in this pull request? Ozone SCM UI uses placeholders such as `{{typestat.portval.toLowerCase()}}` in the HTML which are supposed to be replaced by JavaScript code. However this is the same syntax what knox uses for template variables. If no escaping is used knox will populate the the template variable with an empty string since it has no value. But escaping `{` didn't work originally in rewrite templates (so `\{x\}` resulted literally `\{x\}`). ## How was this patch tested? sandbox topology: ```xml <service> <role>OZONE-SCM</role> <url>http://localhost:1701</url> </service> ``` service.xml ```xml <service role="OZONE-SCM" name="ozone-scm" version="1.2.0"> <metadata> <type>UI</type> <context>/ozone-scm/index.html?host={{BACKEND_HOST}}</context> <shortDesc>OZONE SCM UI</shortDesc> </metadata> <routes> <route path="/ozone-scm/index.html"> <rewrite apply="OZONE-SCM/ozone-scm/inbound/request" to="request.url"/> <rewrite apply="OZONE-SCM/ozone-scm/outbound/response" to="response.body"/> </route> </routes> <dispatch classname="org.apache.knox.gateway.dispatch.URLDecodingDispatch" ha-classname="org.apache.knox.gateway.dispatch.URLDecodingDispatch"/> </service> ```` rewrite.xml ```xml <rules> <rule dir="IN" name="OZONE-SCM/ozone-scm/inbound/request" pattern="*://*:*/**/ozone-scm/{path=**}?host={host}?{**}"> <rewrite template="{host}/{path=**}?{**}"/> </rule> <rule dir="OUT" name="OZONE-SCM/ozone-scm/outbound/datanode/address"> <rewrite template="{gateway.url}/ozone-scm/datanode/index.html?host=\{\{typestat.portval.toLowerCase()\}\}://\{\{typestat.hostname\}\}:\{\{typestat.portno\}\}"/> </rule> <filter name="OZONE-SCM/ozone-scm/outbound/response"> <content type="*/html"> <apply path="\{\{typestat\.portval\.toLowerCase\(\)\}\}\:\/\/\{\{typestat\.hostname\}\}\:\{\{typestat\.portno\}\}" rule="OZONE-SCM/ozone-scm/outbound/datanode/address"/> </content> </filter> </rules> ``` Http server to emulate the service ```smalltalk Teapot on GET: 'index.html' -> '<a href="{{typestat.portval.toLowerCase()}}://{{typestat.hostname}}:{{typestat.portno}}">{{typestat.hostname}}</a>'; start. ``` URL to check: https://localhost:8443/gateway/sandbox/ozone-scm/index.html?host=http://localhost:1701 Result: ```html <a href="https://localhost:8443/gateway/sandbox/ozone-scm/datanode/index.html?host={{typestat.portval.toLowerCase()}}://{{typestat.hostname}}:{{typestat.portno}}">{{typestat.hostname}}</a> ``` Issue Time Tracking ------------------- Worklog Id: (was: 869110) Remaining Estimate: 0h Time Spent: 10m > Some special characters in the rewrite rule cannot be escaped > ------------------------------------------------------------- > > Key: KNOX-2931 > URL: https://issues.apache.org/jira/browse/KNOX-2931 > Project: Apache Knox > Issue Type: Task > Reporter: Attila Magyar > Assignee: Attila Magyar > Priority: Major > Time Spent: 10m > Remaining Estimate: 0h > > HTML content: > {code} > <td><a > href="{{typestat.portval.toLowerCase()}}://{{typestat.hostname}}:{{typestat.portno}}" > target="_blank">{{typestat.hostname}}</a></td> > {code} > Rule: > {code} > <rule dir="OUT" name="OZONE-SCM/ozone-scm/outbound/datanode/address"> > <match > pattern="{{typestat.portval.toLowerCase()}}://{{typestat.hostname}}:{{typestat.portno}}"/> > <rewrite > template="{gateway.url}/ozone-scm/datanode/index.html?host={{typestat.portval.toLowerCase()}}://{{typestat.hostname}}:{{typestat.portno}} > "/> > </rule> > {code} > The goal is to prepend knox URL in front of the href and have: > {code} > https://KNOX/gateway/topology/service?host={{typestat.portval.toLowerCase()}}://{{typestat.hostname}}:{{typestat.portno}} > {code} > It seems that the {{ ... }} part is interpreted as a place holder and the > host part is completely omitted. > Interestingly adding a dummy space at the end solves it. > cc: [~zitadombi] -- This message was sent by Atlassian Jira (v8.20.10#820010)