Skip to content

Commit

Permalink
[ISSUE #4517]Fix Webhook callback path is not a valid Nacos dataId (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
Pil0tXia authored Oct 28, 2023
1 parent f948cc5 commit 11def17
Showing 1 changed file with 7 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,6 @@
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;
Expand Down Expand Up @@ -193,19 +190,16 @@ public List<WebHookConfig> queryWebHookConfigByManufacturer(final WebHookConfig
}

/**
* @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) {
Expand Down

0 comments on commit 11def17

Please sign in to comment.