aboutsummaryrefslogtreecommitdiffstats
path: root/Source
diff options
context:
space:
mode:
authorMax <post@wickenrode.com>2017-02-12 20:49:31 +0100
committerMax <post@wickenrode.com>2017-02-12 20:49:31 +0100
commitd2b1a5b84cb295eba8617f7e80681e0eeca46f0d (patch)
tree82dd73fb5c23849be2aa8c5df3695293410229e7 /Source
parentaee6a009a5355aa3c7c91f885685868e5294e71c (diff)
downloadsequelpro-d2b1a5b84cb295eba8617f7e80681e0eeca46f0d.tar.gz
sequelpro-d2b1a5b84cb295eba8617f7e80681e0eeca46f0d.tar.bz2
sequelpro-d2b1a5b84cb295eba8617f7e80681e0eeca46f0d.zip
Add unit tests and fix a bug in JSON formatter
Diffstat (limited to 'Source')
-rw-r--r--Source/SPJSONFormatter.m8
1 files changed, 4 insertions, 4 deletions
diff --git a/Source/SPJSONFormatter.m b/Source/SPJSONFormatter.m
index 05cc2992..258845c9 100644
--- a/Source/SPJSONFormatter.m
+++ b/Source/SPJSONFormatter.m
@@ -62,11 +62,11 @@ static char GetNextANSIChar(SPJSONTokenizerState *stateInfo);
return nil;
}
- if(curToken.tok == JSON_TOK_SQUARE_BRACE_CLOSE || curToken.tok == JSON_TOK_CURLY_BRACE_CLOSE)
+ if(idLevel > 0 && (curToken.tok == JSON_TOK_SQUARE_BRACE_CLOSE || curToken.tok == JSON_TOK_CURLY_BRACE_CLOSE))
idLevel--;
- //if this token is a "]" or "}" and there was no "[" or "{" directly before it, add a linebreak before
- if(prevTokenType != JSON_TOK_CURLY_BRACE_OPEN && prevTokenType != JSON_TOK_SQUARE_BRACE_OPEN && (curToken.tok == JSON_TOK_SQUARE_BRACE_CLOSE || curToken.tok == JSON_TOK_CURLY_BRACE_CLOSE)) {
+ //if this token is a "]" or "}" and there was no ",", "[" or "{" directly before it, add a linebreak before
+ if(prevTokenType != JSON_TOK_CURLY_BRACE_OPEN && prevTokenType != JSON_TOK_SQUARE_BRACE_OPEN && prevTokenType != JSON_TOK_COMMA && (curToken.tok == JSON_TOK_SQUARE_BRACE_CLOSE || curToken.tok == JSON_TOK_CURLY_BRACE_CLOSE)) {
[formatted appendString:@"\n"];
needIndent = YES;
}
@@ -255,7 +255,7 @@ int SPJSONTokenizerInit(NSString *input, SPJSONTokenizerState *stateInfo) {
stateInfo->ctxt = JSON_ROOT_CONTEXT;
stateInfo->pos = 0;
stateInfo->str = [input UTF8String];
- stateInfo->len = strlen(stateInfo->str); //we deem -[NSString UTF8String] to be a safe source
+ stateInfo->len = [input lengthOfBytesUsingEncoding:NSUTF8StringEncoding];
return 0;
}