mirror of
https://github.com/kennethreitz-archive/gitx.git
synced 2026-06-05 23:40:18 +00:00
Fix bug in encoding parsing
If a commit had invalid UTF-8 characters in them -- like one in git.git for example -- then the revparsing would stop halfway through. This patch first tries UTF-8 enconding, and if that fails, falls back to ASCII encoding.
This commit is contained in:
+7
-1
@@ -47,7 +47,10 @@
|
||||
switch (*(buffer + bytesReceived - 1)) {
|
||||
case '\n':
|
||||
buffer[bytesReceived-1] = '\0';
|
||||
return [NSString stringWithCString: buffer encoding: NSUTF8StringEncoding];
|
||||
NSString* s = [NSString stringWithCString: buffer encoding: NSUTF8StringEncoding];
|
||||
if ([s length] == 0)
|
||||
s = [NSString stringWithCString: buffer encoding: NSASCIIStringEncoding];
|
||||
return s;
|
||||
case '\r':
|
||||
bytesReceived--;
|
||||
}
|
||||
@@ -55,6 +58,9 @@
|
||||
|
||||
buffer[bytesReceived-1] = '\0';
|
||||
NSString *retVal = [NSString stringWithCString: buffer encoding: NSUTF8StringEncoding];
|
||||
if ([retVal length] == 0)
|
||||
retVal = [NSString stringWithCString: buffer encoding: NSASCIIStringEncoding];
|
||||
|
||||
free(buffer);
|
||||
return retVal;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user