Skip to content

Commit 69614d6

Browse files
committed
fix: preserve plus signs in param flow rules
1 parent a3f40ba commit 69614d6

2 files changed

Lines changed: 55 additions & 7 deletions

File tree

sentinel-extension/sentinel-parameter-flow-control/src/main/java/com/alibaba/csp/sentinel/command/handler/ModifyParamFlowRulesCommandHandler.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,6 @@
1515
*/
1616
package com.alibaba.csp.sentinel.command.handler;
1717

18-
import java.net.URLDecoder;
1918
import java.util.List;
2019

2120
import com.alibaba.csp.sentinel.command.CommandHandler;
@@ -44,12 +43,6 @@ public CommandResponse<String> handle(CommandRequest request) {
4443
if (StringUtil.isBlank(data)) {
4544
return CommandResponse.ofFailure(new IllegalArgumentException("Bad data"));
4645
}
47-
try {
48-
data = URLDecoder.decode(data, "utf-8");
49-
} catch (Exception e) {
50-
RecordLog.info("Decode rule data error", e);
51-
return CommandResponse.ofFailure(e, "decode rule data error");
52-
}
5346

5447
RecordLog.info("[API Server] Receiving rule change (type:parameter flow rule): {}", data);
5548

Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Copyright 1999-2018 Alibaba Group Holding Ltd.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package com.alibaba.csp.sentinel.slots.block.flow.param;
17+
18+
import java.util.Collections;
19+
import java.util.List;
20+
21+
import com.alibaba.csp.sentinel.command.CommandRequest;
22+
import com.alibaba.csp.sentinel.command.CommandResponse;
23+
import com.alibaba.csp.sentinel.command.handler.ModifyParamFlowRulesCommandHandler;
24+
import com.alibaba.fastjson.JSON;
25+
import org.junit.After;
26+
import org.junit.Test;
27+
28+
import static org.junit.Assert.assertEquals;
29+
import static org.junit.Assert.assertTrue;
30+
31+
public class ModifyParamFlowRulesCommandHandlerTest {
32+
33+
@After
34+
public void tearDown() {
35+
ParamFlowRuleManager.loadRules(Collections.<ParamFlowRule>emptyList());
36+
}
37+
38+
@Test
39+
public void testHandleDecodedDataPreservesPlusInParamFlowItem() {
40+
ParamFlowRule rule = new ParamFlowRule("test-resource")
41+
.setParamIdx(0)
42+
.setCount(1);
43+
rule.setParamFlowItemList(Collections.singletonList(new ParamFlowItem("a+b", 3, String.class.getName())));
44+
45+
CommandRequest request = new CommandRequest();
46+
request.addParam("data", JSON.toJSONString(Collections.singletonList(rule)));
47+
48+
CommandResponse<String> response = new ModifyParamFlowRulesCommandHandler().handle(request);
49+
50+
assertTrue(response.isSuccess());
51+
List<ParamFlowRule> rules = ParamFlowRuleManager.getRulesOfResource("test-resource");
52+
assertEquals(1, rules.size());
53+
assertEquals(Integer.valueOf(3), rules.get(0).getParsedHotItems().get("a+b"));
54+
}
55+
}

0 commit comments

Comments
 (0)