Skip to content

Commit 51ef382

Browse files
committed
fixed DefaultParamChecker and DefaultParamCheckerTest codeStyle
1 parent 1e1444a commit 51ef382

File tree

2 files changed

+45
-48
lines changed

2 files changed

+45
-48
lines changed

common/src/main/java/com/alibaba/nacos/common/paramcheck/DefaultParamChecker.java

+42-43
Original file line numberDiff line numberDiff line change
@@ -30,32 +30,32 @@
3030
* @author zhuoguang
3131
*/
3232
public class DefaultParamChecker extends AbstractParamChecker {
33-
33+
3434
private Pattern namespaceShowNamePattern;
35-
35+
3636
private Pattern namespaceIdPattern;
37-
37+
3838
private Pattern dataIdPattern;
39-
39+
4040
private Pattern serviceNamePattern;
41-
41+
4242
private Pattern groupPattern;
43-
43+
4444
private Pattern clusterPattern;
45-
45+
4646
private Pattern ipPattern;
47-
47+
4848
private static final String CHECKER_TYPE = "default";
49-
49+
5050
private static final String MAX_METADATA_LENGTH_PROP_NAME = "nacos.naming.service.metadata.length";
51-
51+
5252
private static final String MAX_METADATA_LENGTH_ENV_NAME = "NACOS_NAMING_SERVICE_METADATA_LENGTH";
53-
53+
5454
@Override
5555
public String getCheckerType() {
5656
return CHECKER_TYPE;
5757
}
58-
58+
5959
@Override
6060
public ParamCheckResponse checkParamInfoList(List<ParamInfo> paramInfos) {
6161
ParamCheckResponse paramCheckResponse = new ParamCheckResponse();
@@ -72,14 +72,14 @@ public ParamCheckResponse checkParamInfoList(List<ParamInfo> paramInfos) {
7272
paramCheckResponse.setSuccess(true);
7373
return paramCheckResponse;
7474
}
75-
75+
7676
@Override
7777
public void initParamCheckRule() {
7878
this.paramCheckRule = new ParamCheckRule();
7979
initFormatPattern();
8080
replaceParamCheckRuleByEnv();
8181
}
82-
82+
8383
private void initFormatPattern() {
8484
this.namespaceShowNamePattern = Pattern.compile(this.paramCheckRule.namespaceShowNamePatternString);
8585
this.namespaceIdPattern = Pattern.compile(this.paramCheckRule.namespaceIdPatternString);
@@ -89,7 +89,7 @@ private void initFormatPattern() {
8989
this.clusterPattern = Pattern.compile(this.paramCheckRule.clusterPatternString);
9090
this.ipPattern = Pattern.compile(this.paramCheckRule.ipPatternString);
9191
}
92-
92+
9393
/**
9494
* if environment variables exists, it will be replaced.
9595
*/
@@ -99,7 +99,7 @@ private void replaceParamCheckRuleByEnv() {
9999
this.paramCheckRule.maxMetadataLength = NumberUtils.toInt(maxMetadataLength);
100100
}
101101
}
102-
102+
103103
/**
104104
* Check param info format.
105105
*
@@ -155,7 +155,7 @@ public ParamCheckResponse checkParamInfoFormat(ParamInfo paramInfo) {
155155
paramCheckResponse.setSuccess(true);
156156
return paramCheckResponse;
157157
}
158-
158+
159159
/**
160160
* Check namespace show name format.
161161
*
@@ -182,7 +182,7 @@ public ParamCheckResponse checkNamespaceShowNameFormat(String namespaceShowName)
182182
paramCheckResponse.setSuccess(true);
183183
return paramCheckResponse;
184184
}
185-
185+
186186
/**
187187
* Check namespace id format.
188188
*
@@ -209,7 +209,7 @@ public ParamCheckResponse checkNamespaceIdFormat(String namespaceId) {
209209
paramCheckResponse.setSuccess(true);
210210
return paramCheckResponse;
211211
}
212-
212+
213213
/**
214214
* Check data id format.
215215
*
@@ -224,8 +224,8 @@ public ParamCheckResponse checkDataIdFormat(String dataId) {
224224
}
225225
if (dataId.length() > paramCheckRule.maxDataIdLength) {
226226
paramCheckResponse.setSuccess(false);
227-
paramCheckResponse.setMessage(String.format("Param 'dataId' is illegal, the param length should not exceed %d.",
228-
paramCheckRule.maxDataIdLength));
227+
paramCheckResponse.setMessage(
228+
String.format("Param 'dataId' is illegal, the param length should not exceed %d.", paramCheckRule.maxDataIdLength));
229229
return paramCheckResponse;
230230
}
231231
if (!dataIdPattern.matcher(dataId).matches()) {
@@ -236,7 +236,7 @@ public ParamCheckResponse checkDataIdFormat(String dataId) {
236236
paramCheckResponse.setSuccess(true);
237237
return paramCheckResponse;
238238
}
239-
239+
240240
/**
241241
* Check service name format.
242242
*
@@ -251,8 +251,8 @@ public ParamCheckResponse checkServiceNameFormat(String serviceName) {
251251
}
252252
if (serviceName.length() > paramCheckRule.maxServiceNameLength) {
253253
paramCheckResponse.setSuccess(false);
254-
paramCheckResponse.setMessage(String.format("Param 'serviceName' is illegal, the param length should not exceed %d.",
255-
paramCheckRule.maxServiceNameLength));
254+
paramCheckResponse.setMessage(
255+
String.format("Param 'serviceName' is illegal, the param length should not exceed %d.", paramCheckRule.maxServiceNameLength));
256256
return paramCheckResponse;
257257
}
258258
if (!serviceNamePattern.matcher(serviceName).matches()) {
@@ -263,7 +263,7 @@ public ParamCheckResponse checkServiceNameFormat(String serviceName) {
263263
paramCheckResponse.setSuccess(true);
264264
return paramCheckResponse;
265265
}
266-
266+
267267
/**
268268
* Check group format.
269269
*
@@ -278,8 +278,8 @@ public ParamCheckResponse checkGroupFormat(String group) {
278278
}
279279
if (group.length() > paramCheckRule.maxGroupLength) {
280280
paramCheckResponse.setSuccess(false);
281-
paramCheckResponse.setMessage(String.format("Param 'group' is illegal, the param length should not exceed %d.",
282-
paramCheckRule.maxGroupLength));
281+
paramCheckResponse.setMessage(
282+
String.format("Param 'group' is illegal, the param length should not exceed %d.", paramCheckRule.maxGroupLength));
283283
return paramCheckResponse;
284284
}
285285
if (!groupPattern.matcher(group).matches()) {
@@ -290,7 +290,7 @@ public ParamCheckResponse checkGroupFormat(String group) {
290290
paramCheckResponse.setSuccess(true);
291291
return paramCheckResponse;
292292
}
293-
293+
294294
/**
295295
* Check cluster format.
296296
*
@@ -313,7 +313,7 @@ public ParamCheckResponse checkClusterFormat(String clusterString) {
313313
paramCheckResponse.setSuccess(true);
314314
return paramCheckResponse;
315315
}
316-
316+
317317
/**
318318
* Check single cluster format.
319319
*
@@ -326,11 +326,11 @@ public ParamCheckResponse checkSingleClusterFormat(String cluster) {
326326
paramCheckResponse.setSuccess(true);
327327
return paramCheckResponse;
328328
}
329-
329+
330330
if (cluster.length() > paramCheckRule.maxClusterLength) {
331331
paramCheckResponse.setSuccess(false);
332-
paramCheckResponse.setMessage(String.format("Param 'cluster' is illegal, the param length should not exceed %d.",
333-
paramCheckRule.maxClusterLength));
332+
paramCheckResponse.setMessage(
333+
String.format("Param 'cluster' is illegal, the param length should not exceed %d.", paramCheckRule.maxClusterLength));
334334
return paramCheckResponse;
335335
}
336336
if (!clusterPattern.matcher(cluster).matches()) {
@@ -341,7 +341,7 @@ public ParamCheckResponse checkSingleClusterFormat(String cluster) {
341341
paramCheckResponse.setSuccess(true);
342342
return paramCheckResponse;
343343
}
344-
344+
345345
/**
346346
* Check ip format.
347347
*
@@ -356,8 +356,7 @@ public ParamCheckResponse checkIpFormat(String ip) {
356356
}
357357
if (ip.length() > paramCheckRule.maxIpLength) {
358358
paramCheckResponse.setSuccess(false);
359-
paramCheckResponse.setMessage(String.format("Param 'ip' is illegal, the param length should not exceed %d.",
360-
paramCheckRule.maxIpLength));
359+
paramCheckResponse.setMessage(String.format("Param 'ip' is illegal, the param length should not exceed %d.", paramCheckRule.maxIpLength));
361360
return paramCheckResponse;
362361
}
363362
if (!ipPattern.matcher(ip).matches()) {
@@ -368,7 +367,7 @@ public ParamCheckResponse checkIpFormat(String ip) {
368367
paramCheckResponse.setSuccess(true);
369368
return paramCheckResponse;
370369
}
371-
370+
372371
/**
373372
* Check port format.
374373
*
@@ -386,20 +385,20 @@ public ParamCheckResponse checkPortFormat(String port) {
386385
portInt = Integer.parseInt(port);
387386
} catch (Exception e) {
388387
paramCheckResponse.setSuccess(false);
389-
paramCheckResponse.setMessage(String.format("Param 'port' is illegal, the value should be between %d and %d.",
390-
paramCheckRule.minPort, paramCheckRule.maxPort));
388+
paramCheckResponse.setMessage(
389+
String.format("Param 'port' is illegal, the value should be between %d and %d.", paramCheckRule.minPort, paramCheckRule.maxPort));
391390
return paramCheckResponse;
392391
}
393392
if (portInt > paramCheckRule.maxPort || portInt < paramCheckRule.minPort) {
394393
paramCheckResponse.setSuccess(false);
395-
paramCheckResponse.setMessage(String.format("Param 'port' is illegal, the value should be between %d and %d.",
396-
paramCheckRule.minPort, paramCheckRule.maxPort));
394+
paramCheckResponse.setMessage(
395+
String.format("Param 'port' is illegal, the value should be between %d and %d.", paramCheckRule.minPort, paramCheckRule.maxPort));
397396
return paramCheckResponse;
398397
}
399398
paramCheckResponse.setSuccess(true);
400399
return paramCheckResponse;
401400
}
402-
401+
403402
/**
404403
* Check metadata format.
405404
*
@@ -423,8 +422,8 @@ public ParamCheckResponse checkMetadataFormat(Map<String, String> metadata) {
423422
}
424423
if (totalLength > paramCheckRule.maxMetadataLength) {
425424
paramCheckResponse.setSuccess(false);
426-
paramCheckResponse.setMessage(String.format("Param 'Metadata' is illegal, the param length should not exceed %d.",
427-
paramCheckRule.maxMetadataLength));
425+
paramCheckResponse.setMessage(
426+
String.format("Param 'Metadata' is illegal, the param length should not exceed %d.", paramCheckRule.maxMetadataLength));
428427
return paramCheckResponse;
429428
}
430429
paramCheckResponse.setSuccess(true);

common/src/test/java/com/alibaba/nacos/common/paramcheck/DefaultParamCheckerTest.java

+3-5
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
class DefaultParamCheckerTest {
3333

3434
DefaultParamChecker paramChecker;
35-
35+
3636
int maxMetadataLength = RandomUtils.nextInt(1024, 10240);
3737

3838
@BeforeEach
@@ -79,8 +79,7 @@ void testCheckParamInfoForNamespaceShowName() {
7979
paramInfo.setNamespaceShowName("hsbfkj@$!#khdkad");
8080
actual = paramChecker.checkParamInfoList(paramInfos);
8181
assertFalse(actual.isSuccess());
82-
assertEquals("Param 'namespaceShowName' is illegal, illegal characters should not appear in the param.",
83-
actual.getMessage());
82+
assertEquals("Param 'namespaceShowName' is illegal, illegal characters should not appear in the param.", actual.getMessage());
8483
// Success
8584
paramInfo.setNamespaceShowName("测试");
8685
actual = paramChecker.checkParamInfoList(paramInfos);
@@ -102,8 +101,7 @@ void testCheckParamInfoForNamespaceId() {
102101
paramInfo.setNamespaceId("hsbfkj@$!#khdkad");
103102
actual = paramChecker.checkParamInfoList(paramInfos);
104103
assertFalse(actual.isSuccess());
105-
assertEquals("Param 'namespaceId/tenant' is illegal, illegal characters should not appear in the param.",
106-
actual.getMessage());
104+
assertEquals("Param 'namespaceId/tenant' is illegal, illegal characters should not appear in the param.", actual.getMessage());
107105
// Success
108106
paramInfo.setNamespaceId("123-ashdal");
109107
actual = paramChecker.checkParamInfoList(paramInfos);

0 commit comments

Comments
 (0)