Skip to content

Commit 11def17

Browse files
authored
[ISSUE #4517]Fix Webhook callback path is not a valid Nacos dataId (#4518)
1 parent f948cc5 commit 11def17

File tree

1 file changed

+7
-13
lines changed

1 file changed

+7
-13
lines changed

eventmesh-webhook/eventmesh-webhook-admin/src/main/java/org/apache/eventmesh/webhook/admin/NacosWebHookConfigOperation.java

Lines changed: 7 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -28,9 +28,6 @@
2828
import org.apache.eventmesh.webhook.api.WebHookConfigOperation;
2929
import org.apache.eventmesh.webhook.api.WebHookOperationConstant;
3030

31-
import java.io.UnsupportedEncodingException;
32-
import java.net.URLEncoder;
33-
import java.nio.charset.StandardCharsets;
3431
import java.util.ArrayList;
3532
import java.util.List;
3633
import java.util.Properties;
@@ -193,19 +190,16 @@ public List<WebHookConfig> queryWebHookConfigByManufacturer(final WebHookConfig
193190
}
194191

195192
/**
196-
* @param webHookConfig
197-
* @return
193+
* Escape callback path to a valid dataId.
198194
*/
199195
private String getWebHookConfigDataId(final WebHookConfig webHookConfig) {
200-
try {
201-
// use URLEncoder.encode before, because the path may contain some speacial char like '/', which is illegal as a data id.
202-
return URLEncoder.encode(webHookConfig.getCallbackPath(), StandardCharsets.UTF_8.name()) + DATA_ID_EXTENSION;
203-
} catch (UnsupportedEncodingException e) {
204-
if (log.isErrorEnabled()) {
205-
log.error("get webhookConfig dataId {} failed", webHookConfig.getCallbackPath(), e);
206-
}
196+
String dataId = webHookConfig.getCallbackPath();
197+
if (dataId.startsWith("/")) {
198+
// remove the first slash
199+
dataId = dataId.substring(1);
207200
}
208-
return webHookConfig.getCallbackPath() + DATA_ID_EXTENSION;
201+
// then replace the subsequent invalid chars with dots
202+
return dataId.replaceAll("[@#$%^&*,/\\\\]", ".") + DATA_ID_EXTENSION;
209203
}
210204

211205
private String getManuGroupId(final WebHookConfig webHookConfig) {

0 commit comments

Comments
 (0)