Skip to content

Commit 1576d3f

Browse files
authored
Merge pull request alibaba#931 from pythons/ios-feature-localstorage
not allow if key is blank string.
2 parents 35c3966 + 38eae0e commit 1576d3f

File tree

7 files changed

+45
-44
lines changed

7 files changed

+45
-44
lines changed

ios/playground/WeexDemo.xcworkspace/contents.xcworkspacedata

+10
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ios/sdk/WeexSDK.xcodeproj/project.xcworkspace/contents.xcworkspacedata

+7
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

ios/sdk/WeexSDK/Sources/Module/WXStorageModule.m

+8-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
#import "WXThreadSafeMutableDictionary.h"
1212
#import <CommonCrypto/CommonCrypto.h>
1313
#import "WXUtility.h"
14-
#import "WXUtility+Hash.h"
1514

1615
static NSString * const WXStorageDirectory = @"wxstorage";
1716
static NSString * const WXStorageFileName = @"wxstorage.json";
@@ -46,6 +45,10 @@ - (void)getItem:(NSString *)key callback:(WXModuleCallback)callback
4645
callback(@{@"result":@"failed",@"data":@"key must a string!"});
4746
return;
4847
}
48+
if ([WXUtility isBlankString:key]) {
49+
callback(@{@"result":@"failed",@"data":@"invalid_param"});
50+
return ;
51+
}
4952
NSString *value = [self.memory objectForKey:key];
5053
if (value == (id)kCFNull) {
5154
value = [[WXUtility globalCache] objectForKey:key];
@@ -80,6 +83,10 @@ - (void)setItem:(NSString *)key value:(NSString *)value callback:(WXModuleCallba
8083
callback(@{@"result":@"failed",@"data":@"value must a string!"});
8184
return;
8285
}
86+
if ([WXUtility isBlankString:key]) {
87+
callback(@{@"result":@"failed",@"data":@"invalid_param"});
88+
return ;
89+
}
8390
[self setObject:value forKey:key];
8491
callback(@{@"result":@"success"});
8592
}

ios/sdk/WeexSDK/Sources/Utility/WXUtility+Hash.h

-16
This file was deleted.

ios/sdk/WeexSDK/Sources/Utility/WXUtility+Hash.m

-27
This file was deleted.

ios/sdk/WeexSDK/Sources/Utility/WXUtility.h

+6
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@
88

99
#import <Foundation/Foundation.h>
1010
#import <UIKit/UIKit.h>
11+
#import <CommonCrypto/CommonCrypto.h>
1112
#import "WXDefine.h"
1213
#import "WXType.h"
1314
#import "WXLog.h"
@@ -290,4 +291,9 @@ CGPoint WXPixelPointResize(CGPoint value);
290291
*/
291292
+ (NSString *_Nullable)stringWithContentsOfFile:(NSString *_Nonnull)filePath;
292293

294+
/**
295+
* @abstract Returns md5 string.
296+
*
297+
*/
298+
+ (NSString *)md5:(NSString *)string;
293299
@end

ios/sdk/WeexSDK/Sources/Utility/WXUtility.m

+14
Original file line numberDiff line numberDiff line change
@@ -490,4 +490,18 @@ + (NSString *)stringWithContentsOfFile:(NSString *)filePath
490490
return nil;
491491
}
492492

493+
+ (NSString *)md5:(NSString *)string
494+
{
495+
const char *str = string.UTF8String;
496+
unsigned char result[CC_MD5_DIGEST_LENGTH];
497+
CC_MD5(str, (CC_LONG)strlen(str), result);
498+
499+
return [NSString stringWithFormat:@"%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
500+
result[0], result[1], result[2], result[3],
501+
result[4], result[5], result[6], result[7],
502+
result[8], result[9], result[10], result[11],
503+
result[12], result[13], result[14], result[15]
504+
];
505+
}
506+
493507
@end

0 commit comments

Comments
 (0)