XML parsing bughfix.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@20221 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2004-10-13 16:46:09 +00:00
parent 8d263f4559
commit 95daaf5f4c
3 changed files with 15 additions and 3 deletions

View file

@ -1,3 +1,7 @@
2004-10-13 Richard Frith-Macdonald <rfm@gnu.org>
* Source/Additions/GSXML.m: Fix bug escaping XML special chartacters.
2004-10-11 Richard Frith-Macdonald <rfm@gnu.org> 2004-10-11 Richard Frith-Macdonald <rfm@gnu.org>
* Tools/defaults.m: fix for domains and default names contaning * Tools/defaults.m: fix for domains and default names contaning

View file

@ -4034,9 +4034,10 @@ static BOOL warned = NO; if (warned == NO) { warned = YES; NSLog(@"WARNING, use
- (NSString*) stringByEscapingXML - (NSString*) stringByEscapingXML
{ {
unsigned length = [self length]; unsigned length = [self length];
unsigned output = length; unsigned output = 0;
unichar *from; unichar *from;
unsigned i = 0; unsigned i = 0;
BOOL escape = NO;
from = NSZoneMalloc (NSDefaultMallocZone(), sizeof(unichar) * length); from = NSZoneMalloc (NSDefaultMallocZone(), sizeof(unichar) * length);
[self getCharacters: from]; [self getCharacters: from];
@ -4052,15 +4053,18 @@ static BOOL warned = NO; if (warned == NO) { warned = YES; NSLog(@"WARNING, use
case '"': case '"':
case '\'': case '\'':
output += 6; output += 6;
escape = YES;
break; break;
case '&': case '&':
output += 5; output += 5;
escape = YES;
break; break;
case '<': case '<':
case '>': case '>':
output += 4; output += 4;
escape = YES;
break; break;
default: default:
@ -4075,13 +4079,15 @@ static BOOL warned = NO; if (warned == NO) { warned = YES; NSLog(@"WARNING, use
output++; output++;
c /= 10; c /= 10;
} }
escape = YES;
} }
output++;
break; break;
} }
} }
} }
if (output > length) if (escape == YES)
{ {
unichar *to; unichar *to;
unsigned j = 0; unsigned j = 0;

View file

@ -1976,6 +1976,7 @@ main(int argc, char **argv, char **env)
{ {
if (hDate == nil || [gDate earlierDate: hDate] == hDate) if (hDate == nil || [gDate earlierDate: hDate] == hDate)
{ {
NSData *d;
GSXMLNode *root; GSXMLNode *root;
GSXMLParser *parser; GSXMLParser *parser;
AGSIndex *localRefs; AGSIndex *localRefs;
@ -2016,7 +2017,8 @@ main(int argc, char **argv, char **env)
[html setLocalRefs: localRefs]; [html setLocalRefs: localRefs];
[html setInstanceVariablesAtEnd: instanceVarsAtEnd]; [html setInstanceVariablesAtEnd: instanceVarsAtEnd];
generated = [html outputDocument: root]; generated = [html outputDocument: root];
if ([generated writeToFile: htmlfile atomically: YES] == NO) d = [generated dataUsingEncoding: NSUTF8StringEncoding];
if ([d writeToFile: htmlfile atomically: YES] == NO)
{ {
NSLog(@"Sorry unable to write %@", htmlfile); NSLog(@"Sorry unable to write %@", htmlfile);
} }