This is an automated email from the ASF dual-hosted git repository.
mxsm pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/eventmesh.git
The following commit(s) were added to refs/heads/master by this push:
new 11def17e8 [ISSUE #4517]Fix Webhook callback path is not a valid Nacos
dataId (#4518)
11def17e8 is described below
commit 11def17e8bd41c9ff5180926cfdac9aa020af18e
Author: Pil0tXia <[email protected]>
AuthorDate: Sat Oct 28 09:42:31 2023 +0800
[ISSUE #4517]Fix Webhook callback path is not a valid Nacos dataId (#4518)
---
.../webhook/admin/NacosWebHookConfigOperation.java | 20 +++++++-------------
1 file changed, 7 insertions(+), 13 deletions(-)
diff --git
a/eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/admin/NacosWebHookConfigOperation.java
b/eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/admin/NacosWebHookConfigOperation.java
index dad3c6af9..495b9ae79 100644
---
a/eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/admin/NacosWebHookConfigOperation.java
+++
b/eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/admin/NacosWebHookConfigOperation.java
@@ -28,9 +28,6 @@ import org.apache.eventmesh.webhook.api.WebHookConfig;
import org.apache.eventmesh.webhook.api.WebHookConfigOperation;
import org.apache.eventmesh.webhook.api.WebHookOperationConstant;
-import java.io.UnsupportedEncodingException;
-import java.net.URLEncoder;
-import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;
@@ -193,19 +190,16 @@ public class NacosWebHookConfigOperation implements
WebHookConfigOperation {
}
/**
- * @param webHookConfig
- * @return
+ * Escape callback path to a valid dataId.
*/
private String getWebHookConfigDataId(final WebHookConfig webHookConfig) {
- try {
- // use URLEncoder.encode before, because the path may contain some
speacial char like '/', which is illegal as a data id.
- return URLEncoder.encode(webHookConfig.getCallbackPath(),
StandardCharsets.UTF_8.name()) + DATA_ID_EXTENSION;
- } catch (UnsupportedEncodingException e) {
- if (log.isErrorEnabled()) {
- log.error("get webhookConfig dataId {} failed",
webHookConfig.getCallbackPath(), e);
- }
+ String dataId = webHookConfig.getCallbackPath();
+ if (dataId.startsWith("/")) {
+ // remove the first slash
+ dataId = dataId.substring(1);
}
- return webHookConfig.getCallbackPath() + DATA_ID_EXTENSION;
+ // then replace the subsequent invalid chars with dots
+ return dataId.replaceAll("[@#$%^&*,/\\\\]", ".") + DATA_ID_EXTENSION;
}
private String getManuGroupId(final WebHookConfig webHookConfig) {
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]