mirror of
https://github.com/gnustep/libs-base.git
synced 2025-06-04 10:30:47 +00:00
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:
parent
daa83f8f82
commit
ab6b009343
1 changed files with 14 additions and 3 deletions
|
@ -2917,7 +2917,7 @@ unfold(const unsigned char *src, const unsigned char *end, BOOL *folded)
|
||||||
if (src > beg)
|
if (src > beg)
|
||||||
{
|
{
|
||||||
s = [NSStringClass allocWithZone: NSDefaultMallocZone()];
|
s = [NSStringClass allocWithZone: NSDefaultMallocZone()];
|
||||||
if (flags.isHttp == 1)
|
if (1 == flags.isHttp)
|
||||||
{
|
{
|
||||||
s = [s initWithBytes: beg
|
s = [s initWithBytes: beg
|
||||||
length: src - beg
|
length: src - beg
|
||||||
|
@ -2940,18 +2940,29 @@ unfold(const unsigned char *src, const unsigned char *end, BOOL *folded)
|
||||||
s = [s initWithBytes: beg
|
s = [s initWithBytes: beg
|
||||||
length: src - beg
|
length: src - beg
|
||||||
encoding: _defaultEncoding];
|
encoding: _defaultEncoding];
|
||||||
if (nil == s && _defaultEncoding != NSUTF8StringEncoding)
|
if (nil == s
|
||||||
|
&& _defaultEncoding != NSUTF8StringEncoding)
|
||||||
{
|
{
|
||||||
/* The specified encoding didn't work, but the case
|
/* 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
|
* generally when parsing HTTP, and if the remote
|
||||||
* system (usually browser) is buggy and sending the
|
* system (usually browser) is buggy and sending the
|
||||||
* wrong characterset it's almost certain to be UTF8
|
* wrong characterset it's almost certain to be UTF8
|
||||||
|
* or (for very old browsers) latin1.
|
||||||
*/
|
*/
|
||||||
s = [NSStringClass allocWithZone: NSDefaultMallocZone()];
|
s = [NSStringClass allocWithZone: NSDefaultMallocZone()];
|
||||||
s = [s initWithBytes: beg
|
s = [s initWithBytes: beg
|
||||||
length: src - beg
|
length: src - beg
|
||||||
encoding: NSUTF8StringEncoding];
|
encoding: NSUTF8StringEncoding];
|
||||||
|
if (nil == s
|
||||||
|
&& _defaultEncoding != NSISOLatin1StringEncoding)
|
||||||
|
{
|
||||||
|
s = [NSStringClass
|
||||||
|
allocWithZone: NSDefaultMallocZone()];
|
||||||
|
s = [s initWithBytes: beg
|
||||||
|
length: src - beg
|
||||||
|
encoding: NSISOLatin1StringEncoding];
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (nil == s)
|
if (nil == s)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue