fallback to latin1 if utf8 doesn't work for non-standard encoding

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@37050 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
Richard Frith-MacDonald 2013-09-08 21:02:48 +00:00
parent e3784d6474
commit 838608f42e

View file

@ -2917,7 +2917,7 @@ unfold(const unsigned char *src, const unsigned char *end, BOOL *folded)
if (src > beg)
{
s = [NSStringClass allocWithZone: NSDefaultMallocZone()];
if (flags.isHttp == 1)
if (1 == flags.isHttp)
{
s = [s initWithBytes: beg
length: src - beg
@ -2940,18 +2940,29 @@ unfold(const unsigned char *src, const unsigned char *end, BOOL *folded)
s = [s initWithBytes: beg
length: src - beg
encoding: _defaultEncoding];
if (nil == s && _defaultEncoding != NSUTF8StringEncoding)
if (nil == s
&& _defaultEncoding != NSUTF8StringEncoding)
{
/* The specified encoding didn't work, but the case
* where we would not be paresing a MIME document is
* where we would not be parsing a MIME document is
* generally when parsing HTTP, and if the remote
* system (usually browser) is buggy and sending the
* wrong characterset it's almost certain to be UTF8
* or (for very old browsers) latin1.
*/
s = [NSStringClass allocWithZone: NSDefaultMallocZone()];
s = [s initWithBytes: beg
length: src - beg
encoding: NSUTF8StringEncoding];
if (nil == s
&& _defaultEncoding != NSISOLatin1StringEncoding)
{
s = [NSStringClass
allocWithZone: NSDefaultMallocZone()];
s = [s initWithBytes: beg
length: src - beg
encoding: NSISOLatin1StringEncoding];
}
}
}
if (nil == s)