mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-31 08:41:03 +00:00
Try to be more tolerant handling text/xml
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@21189 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
90c5c054cd
commit
ad198bec78
2 changed files with 68 additions and 4 deletions
|
@ -1,3 +1,9 @@
|
||||||
|
2005-05-04 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/Additions/GSMime.m: If given content of type text/xml without
|
||||||
|
a charset, try to get the charset from the encoding="..." part of the
|
||||||
|
header.
|
||||||
|
|
||||||
2005-04-29 Richard Frith-Macdonald <rfm@gnu.org>
|
2005-04-29 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Source/GSHTTPURLHandle.m: Remove self as an observer of our file
|
* Source/GSHTTPURLHandle.m: Remove self as an observer of our file
|
||||||
|
|
|
@ -2300,8 +2300,58 @@ NSDebugMLLog(@"GSMime", @"Header parsed - %@", info);
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
NSString *charset;
|
NSString *charset;
|
||||||
|
NSString *sub;
|
||||||
|
|
||||||
charset = [typeInfo parameterForKey: @"charset"];
|
charset = [typeInfo parameterForKey: @"charset"];
|
||||||
|
|
||||||
|
/*
|
||||||
|
* For 'text/xml' content where charset is not supplied,
|
||||||
|
* we may be able to get the information from the
|
||||||
|
* header encoding="..." section.
|
||||||
|
*/
|
||||||
|
if (charset == nil
|
||||||
|
&& (sub = [typeInfo objectForKey: @"Subtype"]) != nil
|
||||||
|
&& [sub isEqualToString: @"xml"] == YES)
|
||||||
|
{
|
||||||
|
const unsigned char *ptr = [data bytes];
|
||||||
|
unsigned int length = [data length];
|
||||||
|
unsigned int i;
|
||||||
|
|
||||||
|
for (i = 0; i < length - 10 && i < 500; i++)
|
||||||
|
{
|
||||||
|
if (memcmp(ptr + i, "encoding=\"", 10) == 0)
|
||||||
|
{
|
||||||
|
unsigned start = i + 10;
|
||||||
|
unsigned end = start;
|
||||||
|
|
||||||
|
for (i = start; i < length; i++)
|
||||||
|
{
|
||||||
|
if (ptr[i] == '"')
|
||||||
|
{
|
||||||
|
end = i;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if (end > start)
|
||||||
|
{
|
||||||
|
NSData *d;
|
||||||
|
NSString *c;
|
||||||
|
|
||||||
|
d = [NSData dataWithBytes: ptr + start
|
||||||
|
length: end - start];
|
||||||
|
c = [NSString alloc];
|
||||||
|
c = [c initWithData: d
|
||||||
|
encoding: NSASCIIStringEncoding];
|
||||||
|
if (c != nil)
|
||||||
|
{
|
||||||
|
charset = [c lowercaseString];
|
||||||
|
}
|
||||||
|
}
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
stringEncoding
|
stringEncoding
|
||||||
= [documentClass encodingFromCharset: charset];
|
= [documentClass encodingFromCharset: charset];
|
||||||
}
|
}
|
||||||
|
@ -2311,8 +2361,15 @@ NSDebugMLLog(@"GSMime", @"Header parsed - %@", info);
|
||||||
string = [NSStringClass allocWithZone: NSDefaultMallocZone()];
|
string = [NSStringClass allocWithZone: NSDefaultMallocZone()];
|
||||||
string = [string initWithData: data
|
string = [string initWithData: data
|
||||||
encoding: stringEncoding];
|
encoding: stringEncoding];
|
||||||
[document setContent: string];
|
if (string == nil)
|
||||||
RELEASE(string);
|
{
|
||||||
|
[document setContent: data]; // Can't make string
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
[document setContent: string];
|
||||||
|
RELEASE(string);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -4786,8 +4843,9 @@ static NSCharacterSet *tokenSet = nil;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
[NSException raise: NSInvalidArgumentException
|
[NSException raise: NSInvalidArgumentException
|
||||||
format: @"[%@ -%@] passed bad content",
|
format: @"[%@ -%@] passed bad content: %@",
|
||||||
NSStringFromClass([self class]), NSStringFromSelector(_cmd)];
|
NSStringFromClass([self class]), NSStringFromSelector(_cmd),
|
||||||
|
newContent];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue