Skip to content

Commit ca47099

Browse files
atptroJacksonTian
authored andcommitted
improve validateParameter
1 parent c1ccff0 commit ca47099

File tree

2 files changed

+6
-0
lines changed

2 files changed

+6
-0
lines changed

aliyun-java-sdk-core/src/main/java/com/aliyuncs/utils/ParameterHelper.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@ public static String getUniqueNonce() {
3030
}
3131

3232
public static void validateParameter(String parameter, String parameterName) {
33+
if (null == parameter || "".equals(parameter.trim())) {
34+
return;
35+
}
3336
if (Pattern.matches(ParameterHelper.PATTERN, parameter)) {
3437
return;
3538
}

aliyun-java-sdk-core/src/test/java/com/aliyuncs/utils/ParameterHelperTest.java

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,9 @@ public void getUniqueNonce() {
2424

2525
@Test
2626
public void validateParameterTest() {
27+
ParameterHelper.validateParameter(" ", "regionId");
28+
ParameterHelper.validateParameter("", "regionId");
29+
ParameterHelper.validateParameter(null, "regionId");
2730
ParameterHelper.validateParameter("cn-hangzhou", "regionId");
2831
try {
2932
ParameterHelper.validateParameter("test.test", "regionId");

0 commit comments

Comments
 (0)