| Issue 85: | CJSONScanner crashes on a json like: {"array":[,]} |
‹ Prev
35 of 35
|
| 2 people starred this issue and may be notified of changes. | Back to list |
Please replace the |scanJSONArray:error| in CJSONScanner.m with the following code:
--
- (BOOL)scanJSONArray:(NSArray **)outArray error:(NSError **)outError
{
NSUInteger theScanLocation = [self scanLocation];
if ([self scanCharacter:'['] == NO)
{
if (outError)
{
NSDictionary *theUserInfo = [NSDictionary dictionaryWithObjectsAndKeys:
@"Could not scan array. Array not started by a '{' character.", NSLocalizedDescriptionKey,
NULL];
*outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-7 userInfo:theUserInfo];
}
return(NO);
}
NSMutableArray *theArray = [[NSMutableArray alloc] init];
[self skipWhitespace];
while ([self currentCharacter] != ']')
{
NSString *theValue = NULL;
if ([self scanJSONObject:&theValue error:outError] == NO)
{
[self setScanLocation:theScanLocation];
if (outError)
{
NSDictionary *theUserInfo = [NSDictionary dictionaryWithObjectsAndKeys:
@"Could not scan array. Could not scan a value.", NSLocalizedDescriptionKey,
NULL];
*outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-8 userInfo:theUserInfo];
}
[theArray release];
return(NO);
}
if(theValue == nil)
{
if (outError)
{
NSDictionary *theUserInfo = [NSDictionary dictionaryWithObjectsAndKeys:
@"Could not scan array. Value is NULL.", NSLocalizedDescriptionKey,
NULL];
*outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-9 userInfo:theUserInfo];
}
[theArray release];
return(NO);
}
[theArray addObject:theValue];
[self skipWhitespace];
if ([self scanCharacter:','] == NO)
{
[self skipWhitespace];
if ([self currentCharacter] != ']')
{
[self setScanLocation:theScanLocation];
if (outError)
{
NSDictionary *theUserInfo = [NSDictionary dictionaryWithObjectsAndKeys:
@"Could not scan array. Array not terminated by a ']' character.", NSLocalizedDescriptionKey,
NULL];
*outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-9 userInfo:theUserInfo];
}
[theArray release];
return(NO);
}
break;
}
[self skipWhitespace];
}
[self skipWhitespace];
if ([self scanCharacter:']'] == NO)
{
[self setScanLocation:theScanLocation];
if (outError)
{
NSDictionary *theUserInfo = [NSDictionary dictionaryWithObjectsAndKeys:
@"Could not scan array. Array not terminated by a ']' character.", NSLocalizedDescriptionKey,
NULL];
*outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-10 userInfo:theUserInfo];
}
[theArray release];
return(NO);
}
if (outArray != NULL)
*outArray = [[theArray copy] autorelease];
[theArray release];
return(YES);
}
---
this code has the following check:
if(theValue == nil)
{
if (outError)
{
NSDictionary *theUserInfo = [NSDictionary dictionaryWithObjectsAndKeys:
@"Could not scan array. Value is NULL.", NSLocalizedDescriptionKey,
NULL];
*outError = [NSError errorWithDomain:kJSONScannerErrorDomain code:-9 userInfo:theUserInfo];
}
[theArray release];
return(NO);
}
without this check, it crashes on strings like: {"array":[,]}
Thanks.
Aug 11, 2010
Project Member
#1
jwight
Nov 1, 2010
Fixed in latest github.
Status:
Fixed
|