Skip to content

Commit

Permalink
Replace invalid chars instead of encoding them
Browse files Browse the repository at this point in the history
  • Loading branch information
Pil0tXia committed Oct 27, 2023
1 parent 62935c4 commit 6412dc7
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 6412dc7

Please sign in to comment.