Skip to content
Browse files

avoid incomplete ISO-2022-JP sequences

  • Loading branch information...
1 parent 2c76706 commit cd3fa6069952605ca3b0c48eb1ae523023743a2b @psychs psychs committed
Showing with 13 additions and 2 deletions.
  1. +13 −2 Classes/IRC/IRCClient.m
View
15 Classes/IRC/IRCClient.m
@@ -3659,8 +3659,19 @@ - (void)ircConnectionDidReceive:(NSData*)data
NSString* s = [[[NSString alloc] initWithData:data encoding:enc] autorelease];
if (!s) {
- s = [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease];
- if (!s) return;
+ if (encoding == NSISO2022JPStringEncoding) {
+ // avoid incomplete sequence
+ for (int i=data.length-1; i>0; --i) {
+ NSData* d = [data subdataWithRange:NSMakeRange(0, i)];
+ s = [[[NSString alloc] initWithData:d encoding:enc] autorelease];
+ if (s) break;
+ }
+ }
+
+ if (!s) {
+ s = [[[NSString alloc] initWithData:data encoding:NSASCIIStringEncoding] autorelease];
+ if (!s) return;
+ }
}
IRCMessage* m = [[[IRCMessage alloc] initWithLine:s] autorelease];

0 comments on commit cd3fa60

Please sign in to comment.
Something went wrong with that request. Please try again.