mirror of
https://github.com/gnustep/libs-base.git
synced 2025-05-30 16:30:41 +00:00
Fixups for libxml bug/feature
git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@16702 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
parent
6909094183
commit
cd13d283b2
6 changed files with 135 additions and 12 deletions
|
@ -1,3 +1,11 @@
|
||||||
|
2003-05-12 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
|
* Source/Additions/GSXML.m: New -escapedContent method to provide
|
||||||
|
text with the five entities libxml automatically substitutes even
|
||||||
|
when told not to.
|
||||||
|
* Tools/AGSHtml.m: Use -escapedContent to get text suitable for
|
||||||
|
output in html documents.
|
||||||
|
|
||||||
2003-05-11 Richard Frith-Macdonald <rfm@gnu.org>
|
2003-05-11 Richard Frith-Macdonald <rfm@gnu.org>
|
||||||
|
|
||||||
* Tools/gdomap.8.gz: Added man page adapted from internal docs by
|
* Tools/gdomap.8.gz: Added man page adapted from internal docs by
|
||||||
|
|
|
@ -114,6 +114,7 @@
|
||||||
- (NSDictionary*) attributes;
|
- (NSDictionary*) attributes;
|
||||||
- (NSString*) content;
|
- (NSString*) content;
|
||||||
- (GSXMLDocument*) document;
|
- (GSXMLDocument*) document;
|
||||||
|
- (NSString*) escapedContent;
|
||||||
- (GSXMLAttribute*) firstAttribute;
|
- (GSXMLAttribute*) firstAttribute;
|
||||||
- (GSXMLNode*) firstChild;
|
- (GSXMLNode*) firstChild;
|
||||||
- (GSXMLNode*) firstChildElement;
|
- (GSXMLNode*) firstChildElement;
|
||||||
|
|
|
@ -820,7 +820,13 @@ static NSMapTable *nodeNames = 0;
|
||||||
* entity reference nodes, in this case you should not use this
|
* entity reference nodes, in this case you should not use this
|
||||||
* method to get the content of the element, but should examine
|
* method to get the content of the element, but should examine
|
||||||
* the child nodes of the element individually and perform any
|
* the child nodes of the element individually and perform any
|
||||||
* entity reference you need to do explicitly.
|
* entity reference you need to do explicitly.<br />
|
||||||
|
* NB. There are five standard entities which are automatically
|
||||||
|
* substituted into the content text rather than appearing as
|
||||||
|
* entity nodes in their own right. These are '<', '>', ''',
|
||||||
|
* '"' and '&'. If you with to receive content in which these
|
||||||
|
* characters are represented by the original entity escapes, you need
|
||||||
|
* to use the -escapedContent method.
|
||||||
*/
|
*/
|
||||||
- (NSString*) content
|
- (NSString*) content
|
||||||
{
|
{
|
||||||
|
@ -893,6 +899,112 @@ static NSMapTable *nodeNames = 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* This performs the same function as the -content method, but retains
|
||||||
|
* the standard five entities (&lt;, &gt;, &apos;, &quot;,
|
||||||
|
* and &amp;) which are normally replaced with their standard equivalents
|
||||||
|
* (<, >, ', ", and &).<br />
|
||||||
|
*/
|
||||||
|
- (NSString*) escapedContent
|
||||||
|
{
|
||||||
|
NSString *str = [self content];
|
||||||
|
|
||||||
|
if (str != nil)
|
||||||
|
{
|
||||||
|
static NSCharacterSet *set = nil;
|
||||||
|
|
||||||
|
if (set == nil)
|
||||||
|
{
|
||||||
|
set = [NSCharacterSet characterSetWithCharactersInString: @"<>'\"&"];
|
||||||
|
RETAIN(set);
|
||||||
|
}
|
||||||
|
if ([str rangeOfCharacterFromSet: set].length > 0)
|
||||||
|
{
|
||||||
|
unichar *base;
|
||||||
|
unichar *map;
|
||||||
|
unichar c;
|
||||||
|
unsigned len;
|
||||||
|
unsigned rpos;
|
||||||
|
unsigned wpos;
|
||||||
|
unsigned end = [str length];
|
||||||
|
|
||||||
|
base = NSZoneMalloc(NSDefaultMallocZone(), end * sizeof(unichar));
|
||||||
|
[str getCharacters: base];
|
||||||
|
for (len = rpos = 0; rpos < end; rpos++)
|
||||||
|
{
|
||||||
|
c = base[rpos];
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case '&':
|
||||||
|
len += 5;
|
||||||
|
break;
|
||||||
|
case '<':
|
||||||
|
case '>':
|
||||||
|
len += 4;
|
||||||
|
break;
|
||||||
|
case '\'':
|
||||||
|
case '"':
|
||||||
|
len += 6;
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
len++;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
map = NSZoneMalloc(NSDefaultMallocZone(), len * sizeof(unichar));
|
||||||
|
for (wpos = rpos = 0; rpos < end; rpos++)
|
||||||
|
{
|
||||||
|
c = base[rpos];
|
||||||
|
switch (c)
|
||||||
|
{
|
||||||
|
case '&':
|
||||||
|
map[wpos++] = '&';
|
||||||
|
map[wpos++] = 'a';
|
||||||
|
map[wpos++] = 'm';
|
||||||
|
map[wpos++] = 'p';
|
||||||
|
map[wpos++] = ';';
|
||||||
|
break;
|
||||||
|
case '<':
|
||||||
|
map[wpos++] = '&';
|
||||||
|
map[wpos++] = 'l';
|
||||||
|
map[wpos++] = 't';
|
||||||
|
map[wpos++] = ';';
|
||||||
|
break;
|
||||||
|
case '>':
|
||||||
|
map[wpos++] = '&';
|
||||||
|
map[wpos++] = 'g';
|
||||||
|
map[wpos++] = 't';
|
||||||
|
map[wpos++] = ';';
|
||||||
|
break;
|
||||||
|
case '\'':
|
||||||
|
map[wpos++] = '&';
|
||||||
|
map[wpos++] = 'a';
|
||||||
|
map[wpos++] = 'p';
|
||||||
|
map[wpos++] = 'o';
|
||||||
|
map[wpos++] = 's';
|
||||||
|
map[wpos++] = ';';
|
||||||
|
break;
|
||||||
|
case '"':
|
||||||
|
map[wpos++] = '&';
|
||||||
|
map[wpos++] = 'q';
|
||||||
|
map[wpos++] = 'u';
|
||||||
|
map[wpos++] = 'o';
|
||||||
|
map[wpos++] = 't';
|
||||||
|
map[wpos++] = ';';
|
||||||
|
break;
|
||||||
|
default:
|
||||||
|
map[wpos++] = c;
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
NSZoneFree(NSDefaultMallocZone(), base);
|
||||||
|
str = [[NSString alloc] initWithCharacters: map length: len];
|
||||||
|
AUTORELEASE(str);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return str;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Return the first attribute in this node.
|
* Return the first attribute in this node.
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -922,7 +922,7 @@ NSDictionary *locale)
|
||||||
if (grouping == (const char *) -1)
|
if (grouping == (const char *) -1)
|
||||||
{
|
{
|
||||||
thousands_sep = [locale objectForKey: NSThousandsSeparator];
|
thousands_sep = [locale objectForKey: NSThousandsSeparator];
|
||||||
if (!thousands_sep) thousands_sep = @",";
|
if (thousands_sep == nil) thousands_sep = @",";
|
||||||
|
|
||||||
grouping = ""; // FIXME: grouping info missing in locale?
|
grouping = ""; // FIXME: grouping info missing in locale?
|
||||||
if (*grouping == '\0' || *grouping == CHAR_MAX)
|
if (*grouping == '\0' || *grouping == CHAR_MAX)
|
||||||
|
@ -1405,6 +1405,7 @@ NSDictionary *locale)
|
||||||
NSString *decimal_sep;
|
NSString *decimal_sep;
|
||||||
|
|
||||||
decimal_sep = [locale objectForKey: NSDecimalSeparator];
|
decimal_sep = [locale objectForKey: NSDecimalSeparator];
|
||||||
|
if (decimal_sep == nil) decimal_sep = @".";
|
||||||
|
|
||||||
bp = buf1;
|
bp = buf1;
|
||||||
|
|
||||||
|
@ -1525,6 +1526,7 @@ NSDictionary *locale)
|
||||||
NSString *decimal_sep;
|
NSString *decimal_sep;
|
||||||
|
|
||||||
decimal_sep = [locale objectForKey: NSDecimalSeparator];
|
decimal_sep = [locale objectForKey: NSDecimalSeparator];
|
||||||
|
if (decimal_sep == nil) decimal_sep = @".";
|
||||||
|
|
||||||
bp = buf1;
|
bp = buf1;
|
||||||
|
|
||||||
|
|
|
@ -774,7 +774,7 @@ static NSMutableSet *textNodes = nil;
|
||||||
NSString *text;
|
NSString *text;
|
||||||
NSString *val;
|
NSString *val;
|
||||||
|
|
||||||
text = [children content];
|
text = [children escapedContent];
|
||||||
val = [prop objectForKey: @"id"];
|
val = [prop objectForKey: @"id"];
|
||||||
if (val == nil)
|
if (val == nil)
|
||||||
{
|
{
|
||||||
|
@ -847,7 +847,7 @@ static NSMutableSet *textNodes = nil;
|
||||||
{
|
{
|
||||||
if ([t type] == XML_TEXT_NODE)
|
if ([t type] == XML_TEXT_NODE)
|
||||||
{
|
{
|
||||||
NSString *content = [t content];
|
NSString *content = [t escapedContent];
|
||||||
|
|
||||||
if (content == nil) content = @"";
|
if (content == nil) content = @"";
|
||||||
str = [str stringByAppendingString: content];
|
str = [str stringByAppendingString: content];
|
||||||
|
@ -1182,7 +1182,7 @@ static NSMutableSet *textNodes = nil;
|
||||||
NSString *text;
|
NSString *text;
|
||||||
NSString *val;
|
NSString *val;
|
||||||
|
|
||||||
text = [children content];
|
text = [children escapedContent];
|
||||||
val = [prop objectForKey: @"id"];
|
val = [prop objectForKey: @"id"];
|
||||||
if (val == nil)
|
if (val == nil)
|
||||||
{
|
{
|
||||||
|
@ -1225,7 +1225,7 @@ static NSMutableSet *textNodes = nil;
|
||||||
{
|
{
|
||||||
if ([t type] == XML_TEXT_NODE)
|
if ([t type] == XML_TEXT_NODE)
|
||||||
{
|
{
|
||||||
NSString *content = [t content];
|
NSString *content = [t escapedContent];
|
||||||
|
|
||||||
if (content == nil) content = @"";
|
if (content == nil) content = @"";
|
||||||
str = [str stringByAppendingString: content];
|
str = [str stringByAppendingString: content];
|
||||||
|
@ -1340,7 +1340,7 @@ static NSMutableSet *textNodes = nil;
|
||||||
{
|
{
|
||||||
if ([t type] == XML_TEXT_NODE)
|
if ([t type] == XML_TEXT_NODE)
|
||||||
{
|
{
|
||||||
NSString *content = [t content];
|
NSString *content = [t escapedContent];
|
||||||
|
|
||||||
if (content == nil) content = @"";
|
if (content == nil) content = @"";
|
||||||
sel = [sel stringByAppendingString: content];
|
sel = [sel stringByAppendingString: content];
|
||||||
|
@ -1366,7 +1366,7 @@ static NSMutableSet *textNodes = nil;
|
||||||
{
|
{
|
||||||
if ([t type] == XML_TEXT_NODE)
|
if ([t type] == XML_TEXT_NODE)
|
||||||
{
|
{
|
||||||
NSString *content = [t content];
|
NSString *content = [t escapedContent];
|
||||||
|
|
||||||
if (content == nil) content = @"";
|
if (content == nil) content = @"";
|
||||||
str = [str stringByAppendingString: content];
|
str = [str stringByAppendingString: content];
|
||||||
|
@ -2002,7 +2002,7 @@ NSLog(@"Element '%@' not implemented", name); // FIXME
|
||||||
{
|
{
|
||||||
if ([node type] == XML_TEXT_NODE)
|
if ([node type] == XML_TEXT_NODE)
|
||||||
{
|
{
|
||||||
NSString *str = [node content];
|
NSString *str = [node escapedContent];
|
||||||
|
|
||||||
if (str == nil) str = @"";
|
if (str == nil) str = @"";
|
||||||
[buf appendString: str];
|
[buf appendString: str];
|
||||||
|
@ -2055,7 +2055,7 @@ NSLog(@"Element '%@' not implemented", name); // FIXME
|
||||||
[buf appendString: @"<dt><b>Conforms to:</b></dt>\n"];
|
[buf appendString: @"<dt><b>Conforms to:</b></dt>\n"];
|
||||||
while (node != nil && [[node name] isEqual: @"conform"] == YES)
|
while (node != nil && [[node name] isEqual: @"conform"] == YES)
|
||||||
{
|
{
|
||||||
NSString *text = [[node firstChild] content];
|
NSString *text = [[node firstChild] escapedContent];
|
||||||
|
|
||||||
if (text == nil) text = @"";
|
if (text == nil) text = @"";
|
||||||
[buf appendString: indent];
|
[buf appendString: indent];
|
||||||
|
|
|
@ -1196,9 +1196,9 @@ main(int argc, char **argv, char **env)
|
||||||
AGSIndex *localRefs;
|
AGSIndex *localRefs;
|
||||||
|
|
||||||
parser = [GSXMLParser parserWithContentsOfFile: gsdocfile];
|
parser = [GSXMLParser parserWithContentsOfFile: gsdocfile];
|
||||||
[parser substituteEntities: NO];
|
|
||||||
[parser doValidityChecking: YES];
|
[parser doValidityChecking: YES];
|
||||||
[parser keepBlanks: NO];
|
[parser keepBlanks: NO];
|
||||||
|
[parser substituteEntities: NO];
|
||||||
if ([parser parse] == NO)
|
if ([parser parse] == NO)
|
||||||
{
|
{
|
||||||
NSLog(@"WARNING %@ is not a valid document", gsdocfile);
|
NSLog(@"WARNING %@ is not a valid document", gsdocfile);
|
||||||
|
@ -1485,9 +1485,9 @@ main(int argc, char **argv, char **env)
|
||||||
file, gDate, hDate);
|
file, gDate, hDate);
|
||||||
}
|
}
|
||||||
parser = [GSXMLParser parserWithContentsOfFile: gsdocfile];
|
parser = [GSXMLParser parserWithContentsOfFile: gsdocfile];
|
||||||
[parser substituteEntities: NO];
|
|
||||||
[parser doValidityChecking: YES];
|
[parser doValidityChecking: YES];
|
||||||
[parser keepBlanks: NO];
|
[parser keepBlanks: NO];
|
||||||
|
[parser substituteEntities: NO];
|
||||||
if ([parser parse] == NO)
|
if ([parser parse] == NO)
|
||||||
{
|
{
|
||||||
NSLog(@"WARNING %@ is not a valid document", gsdocfile);
|
NSLog(@"WARNING %@ is not a valid document", gsdocfile);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue