diff options
author | Max Lohrmann <dmoagx@users.noreply.github.com> | 2015-02-17 20:49:03 +0100 |
---|---|---|
committer | Max Lohrmann <dmoagx@users.noreply.github.com> | 2015-02-17 20:49:03 +0100 |
commit | fc02994e768eece82442bed8e6d21134d392b7a1 (patch) | |
tree | 4ad70da996538e16943dc57439d2940108347474 /Frameworks | |
parent | 2fda43e6a54c0c7532d80b9f3f86987ceb772342 (diff) | |
parent | b75d0c396376e0d82eabdfe971436ec1b97a61cf (diff) | |
download | sequelpro-fc02994e768eece82442bed8e6d21134d392b7a1.tar.gz sequelpro-fc02994e768eece82442bed8e6d21134d392b7a1.tar.bz2 sequelpro-fc02994e768eece82442bed8e6d21134d392b7a1.zip |
Merge pull request #2072 from liuteng/master
fallback solution for NSString decode error
Diffstat (limited to 'Frameworks')
3 files changed, 19 insertions, 4 deletions
diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Data Conversion.m b/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Data Conversion.m index 357eb53f..639ff0b9 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Data Conversion.m +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLResult Categories/Data Conversion.m @@ -247,9 +247,9 @@ static inline NSString * _convertStringData(const void *dataBytes, NSUInteger da { // Fast case - if not using a preview length, or if the data length is shorter, return the requested data. - if (previewLength == NSNotFound || dataLength <= previewLength) { - return [[[NSString alloc] initWithBytes:dataBytes length:dataLength encoding:aStringEncoding] autorelease]; - } + if (previewLength == NSNotFound || dataLength <= previewLength) { + return [NSString stringForDataBytes:dataBytes length:dataLength encoding:aStringEncoding]; + } NSUInteger i = 0, characterLength = 0, byteLength = previewLength; uint16_t continuationStart, continuationEnd; @@ -394,7 +394,7 @@ static inline NSString * _convertStringData(const void *dataBytes, NSUInteger da // If returning the full string, use a fast path if (byteLength >= dataLength) { - return [[[NSString alloc] initWithBytes:dataBytes length:dataLength encoding:aStringEncoding] autorelease]; + return [NSString stringForDataBytes:dataBytes length:dataLength encoding:aStringEncoding]; } // Get a string using the calculated details diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLStringAdditions.h b/Frameworks/SPMySQLFramework/Source/SPMySQLStringAdditions.h index bb29c02b..60832c53 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLStringAdditions.h +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLStringAdditions.h @@ -33,5 +33,6 @@ - (NSString *)mySQLBacktickQuotedString; - (NSString *)mySQLTickQuotedString; ++ (NSString *)stringForDataBytes:(const void *)dataBytes length:(NSUInteger)dataLength encoding:(NSStringEncoding)aStringEncoding; @end diff --git a/Frameworks/SPMySQLFramework/Source/SPMySQLStringAdditions.m b/Frameworks/SPMySQLFramework/Source/SPMySQLStringAdditions.m index 39688ea8..f987c98b 100644 --- a/Frameworks/SPMySQLFramework/Source/SPMySQLStringAdditions.m +++ b/Frameworks/SPMySQLFramework/Source/SPMySQLStringAdditions.m @@ -52,4 +52,18 @@ return [NSString stringWithFormat: @"'%@'", [self stringByReplacingOccurrencesOfString:@"'" withString:@"''"]]; } +/** + * Returns the string for the bytes according to the encoding, decode in ASCII if failed + */ ++ (NSString *) stringForDataBytes:(const void *)dataBytes length:(NSUInteger)dataLength encoding:(NSStringEncoding)aStringEncoding +{ + NSString * string = [[[NSString alloc] initWithBytes:dataBytes length:dataLength encoding:aStringEncoding] autorelease]; + + if (string == nil) { + return [[[NSString alloc] initWithBytes:dataBytes length:dataLength encoding:NSASCIIStringEncoding] autorelease]; + } + + return string; +} + @end |