From 1f735799933afb4cc5f4011854cecbf65516c5da Mon Sep 17 00:00:00 2001 From: Andrew Ryan Date: Tue, 10 May 2011 13:23:26 -0400 Subject: [PATCH] Don't crash with multiline gitconfig values. Use `git config -l -z` to get configs. --- PBGitConfig.m | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/PBGitConfig.m b/PBGitConfig.m index 93e38d6..36cb18d 100644 --- a/PBGitConfig.m +++ b/PBGitConfig.m @@ -99,19 +99,20 @@ NSArray* arguments; if (inDir == nil) { - arguments = [NSArray arrayWithObjects:@"config", @"--global", @"-l", nil]; + arguments = [NSArray arrayWithObjects:@"config", @"--global", @"-l", @"-z", nil]; } else { - arguments = [NSArray arrayWithObjects:@"config", @"-l", nil]; + arguments = [NSArray arrayWithObjects:@"config", @"-l", @"-z", nil]; } int ret = 1; NSString* output = [PBEasyPipe outputForCommand:[PBGitBinary path] withArgs:arguments inDir:inDir retValue:&ret]; NSMutableDictionary *result = [NSMutableDictionary dictionary]; if (ret==0) { - NSArray *lines = [output componentsSeparatedByString:@"\n"]; - + NSArray *lines = [output componentsSeparatedByString:@"\0"]; + for (NSString* line in lines) { - NSRange equalsPos = [line rangeOfString:@"="]; + if([line length] == 0) continue; + NSRange equalsPos = [line rangeOfString:@"\n"]; NSString* key = [line substringToIndex:equalsPos.location]; NSString* value = [line substringFromIndex:equalsPos.location+1]; [result setObject:value forKey:key];