|
7 | 7 | // |
8 | 8 |
|
9 | 9 | #import "QCloudCOSXMLEndPoint.h" |
10 | | - |
| 10 | +#import "NSString+RegularExpressionCategory.h" |
11 | 11 | @implementation QCloudCOSXMLEndPoint |
12 | 12 |
|
13 | 13 | - (instancetype) init |
@@ -56,12 +56,33 @@ - (NSURL*) serverURLWithBucket:(NSString *)bucket appID:(NSString *)appID |
56 | 56 | if (!self.useHTTPS) { |
57 | 57 | scheme = @"http"; |
58 | 58 | } |
| 59 | + static NSString *regularExpression = @"[a-zA-Z0-9.-]*"; |
| 60 | + BOOL isLegal = [bucket matchesRegularExpression:regularExpression]; |
| 61 | + NSAssert(isLegal, @"bucket name contains illegal character! It can only contains a-z, A-Z, 0-9, '.' and '-' "); |
| 62 | + if (!isLegal) { |
| 63 | + QCloudLogDebug(@"bucket %@ contains illeagal character, building service url pregress returns immediately", bucket); |
| 64 | + return nil; |
| 65 | + } |
| 66 | + |
59 | 67 | NSString* formattedRegionName = [self formattedRegionName:self.regionName]; |
60 | 68 | NSString* formattedBucketName = [self formattedBucket:bucket withAPPID:appID]; |
61 | 69 | NSURL* serverURL = [NSURL URLWithString:[NSString stringWithFormat:@"%@://%@-%@.%@.%@",scheme,formattedBucketName,appID,formattedRegionName,self.serviceName]]; |
62 | 70 | return serverURL; |
63 | 71 | } |
64 | 72 |
|
| 73 | +- (void)setRegionName:(QCloudRegion)regionName { |
| 74 | + //Region 仅允许由 a-z, A-Z, 0-9, 英文句号. 和 - 构成。 |
| 75 | + NSParameterAssert(regionName); |
| 76 | + static NSString *regularExpression = @"[a-zA-Z0-9.-]*"; |
| 77 | + BOOL isLegal = [regionName matchesRegularExpression:regularExpression]; |
| 78 | + NSAssert(isLegal, @"Region name contains illegal character! It can only contains a-z, A-Z, 0-9, '.' and '-' "); |
| 79 | + if (!isLegal) { |
| 80 | + QCloudLogDebug(@"Region %@ contains illeagal character, setter returns immediately", regionName); |
| 81 | + return ; |
| 82 | + } |
| 83 | + _regionName = regionName; |
| 84 | +} |
| 85 | + |
65 | 86 | - (id)copyWithZone:(NSZone *)zone { |
66 | 87 | QCloudCOSXMLEndPoint* endpoint = [super copyWithZone:nil]; |
67 | 88 | endpoint.regionName = self.regionName; |
|
0 commit comments