|
28 | 28 | import org.apache.eventmesh.webhook.api.WebHookConfigOperation; |
29 | 29 | import org.apache.eventmesh.webhook.api.WebHookOperationConstant; |
30 | 30 |
|
31 | | -import java.io.UnsupportedEncodingException; |
32 | | -import java.net.URLEncoder; |
33 | | -import java.nio.charset.StandardCharsets; |
34 | 31 | import java.util.ArrayList; |
35 | 32 | import java.util.List; |
36 | 33 | import java.util.Properties; |
@@ -193,19 +190,16 @@ public List<WebHookConfig> queryWebHookConfigByManufacturer(final WebHookConfig |
193 | 190 | } |
194 | 191 |
|
195 | 192 | /** |
196 | | - * @param webHookConfig |
197 | | - * @return |
| 193 | + * Escape callback path to a valid dataId. |
198 | 194 | */ |
199 | 195 | 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); |
207 | 200 | } |
208 | | - return webHookConfig.getCallbackPath() + DATA_ID_EXTENSION; |
| 201 | + // then replace the subsequent invalid chars with dots |
| 202 | + return dataId.replaceAll("[@#$%^&*,/\\\\]", ".") + DATA_ID_EXTENSION; |
209 | 203 | } |
210 | 204 |
|
211 | 205 | private String getManuGroupId(final WebHookConfig webHookConfig) { |
|
0 commit comments