Skip to content

Commit e22e6d5

Browse files
liaoyustudentJacksonTian
authored andcommitted
fixed region regex
1 parent a97a4b4 commit e22e6d5

File tree

2 files changed

+40
-12
lines changed

2 files changed

+40
-12
lines changed

aliyun-net-sdk-core.Tests/Units/AcsRequest.cs

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -192,6 +192,10 @@ public void validateParam()
192192
});
193193

194194
acsRequest.RegionId = "";
195+
Assert.Empty(acsRequest.RegionId);
196+
197+
acsRequest.RegionId = null;
198+
Assert.Null(acsRequest.RegionId);
195199
Assert.Throws<ArgumentException>(() =>
196200
{
197201
acsRequest.ProductNetwork = "a.b";
@@ -200,10 +204,22 @@ public void validateParam()
200204
acsRequest.ProductNetwork = "private";
201205
Assert.Equal("private", acsRequest.ProductNetwork);
202206

207+
acsRequest.ProductNetwork = "";
208+
Assert.Empty(acsRequest.ProductNetwork);
209+
210+
acsRequest.ProductNetwork = null;
211+
Assert.Null(acsRequest.ProductNetwork);
212+
203213
Assert.Throws<ArgumentException>(() =>
204214
{
205215
acsRequest.ProductSuffix = "a.b";
206216
});
217+
218+
acsRequest.ProductSuffix = "";
219+
Assert.Empty(acsRequest.ProductSuffix);
220+
221+
acsRequest.ProductSuffix = null;
222+
Assert.Null(acsRequest.ProductSuffix);
207223
}
208224
}
209225

aliyun-net-sdk-core/AcsRequest.cs

Lines changed: 24 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -69,11 +69,15 @@ public virtual string RegionId
6969
}
7070
set
7171
{
72-
var match = Regex.Match(value, "^[a-zA-Z0-9_-]*$");
73-
if (!match.Success)
74-
{
75-
throw new ArgumentException("regionId is invalid", "regionId");
72+
if(!string.IsNullOrEmpty(value))
73+
{
74+
var match = Regex.Match(value, "^[a-zA-Z0-9_-]+$");
75+
if (!match.Success)
76+
{
77+
throw new ArgumentException("regionId is invalid", "regionId");
78+
}
7679
}
80+
7781
regionId = value;
7882
}
7983
}
@@ -91,11 +95,15 @@ public string ProductNetwork
9195
}
9296
set
9397
{
94-
var match = Regex.Match(value, "^[a-zA-Z0-9_-]+$");
95-
if (!match.Success)
96-
{
97-
throw new ArgumentException("productNetwork is invalid", "productNetwork");
98+
if(!string.IsNullOrEmpty(value))
99+
{
100+
var match = Regex.Match(value, "^[a-zA-Z0-9_-]+$");
101+
if (!match.Success)
102+
{
103+
throw new ArgumentException("productNetwork is invalid", "productNetwork");
104+
}
98105
}
106+
99107
productNetwork = value;
100108
}
101109
}
@@ -108,11 +116,15 @@ public string ProductSuffix
108116
}
109117
set
110118
{
111-
var match = Regex.Match(value, "^[a-zA-Z0-9_-]+$");
112-
if (!match.Success)
113-
{
114-
throw new ArgumentException("productSuffix is invalid", "productSuffix");
119+
if(!string.IsNullOrEmpty(value))
120+
{
121+
var match = Regex.Match(value, "^[a-zA-Z0-9_-]+$");
122+
if (!match.Success)
123+
{
124+
throw new ArgumentException("productSuffix is invalid", "productSuffix");
125+
}
115126
}
127+
116128
productSuffix = value;
117129
}
118130
}

0 commit comments

Comments
 (0)