Commit c815505f authored by Daniel Veillard's avatar Daniel Veillard
Browse files

applied patches from Peter Breitenlohner to fix handling of white space

* catalog.c test/catalogs/white* result/catalogs/white*:
  applied patches from Peter Breitenlohner to fix handling
  of white space normalization in public ids and add tests
Daniel
parent e15df587
Fri Jul 16 11:01:40 CEST 2004 Daniel Veillard <daniel@veillard.com>
* catalog.c test/catalogs/white* result/catalogs/white*:
applied patches from Peter Breitenlohner to fix handling
of white space normalization in public ids and add tests
Tue Jul 13 17:24:13 CEST 2004 Daniel Veillard <daniel@veillard.com>
 
* xmlmemory.c: applied a small fix from Steve Hay
......
......@@ -75,6 +75,7 @@ void* __stdcall GetModuleHandleA(const char*);
unsigned long __stdcall GetModuleFileNameA(void*, char*, unsigned long);
#endif
static xmlChar *xmlCatalogNormalizePublic(const xmlChar *pubID);
static int xmlExpandCatalog(xmlCatalogPtr catal, const char *filename);
/************************************************************************
......@@ -254,6 +255,7 @@ static xmlCatalogEntryPtr
xmlNewCatalogEntry(xmlCatalogEntryType type, const xmlChar *name,
const xmlChar *value, const xmlChar *URL, xmlCatalogPrefer prefer) {
xmlCatalogEntryPtr ret;
xmlChar *normid = NULL;
ret = (xmlCatalogEntryPtr) xmlMalloc(sizeof(xmlCatalogEntry));
if (ret == NULL) {
......@@ -264,10 +266,17 @@ xmlNewCatalogEntry(xmlCatalogEntryType type, const xmlChar *name,
ret->parent = NULL;
ret->children = NULL;
ret->type = type;
if (type == XML_CATA_PUBLIC || type == XML_CATA_DELEGATE_PUBLIC) {
normid = xmlCatalogNormalizePublic(name);
if (normid != NULL)
name = (*normid != 0 ? normid : NULL);
}
if (name != NULL)
ret->name = xmlStrdup(name);
else
ret->name = NULL;
if (normid != NULL)
xmlFree(normid);
if (value != NULL)
ret->value = xmlStrdup(value);
else
......@@ -943,6 +952,61 @@ xmlLoadFileContent(const char *filename)
return(content);
}
/**
* xmlCatalogNormalizePublic:
* @pubID: the public ID string
*
* Normalizes the Public Identifier
*
* Implements 6.2. Public Identifier Normalization
* from http://www.oasis-open.org/committees/entity/spec-2001-08-06.html
*
* Returns the new string or NULL, the string must be deallocated
* by the caller.
*/
static xmlChar *
xmlCatalogNormalizePublic(const xmlChar *pubID)
{
int ok = 1;
int white;
const xmlChar *p;
xmlChar *ret;
xmlChar *q;
if (pubID == NULL)
return(NULL);
white = 1;
for (p = pubID;*p != 0 && ok;p++) {
if (!xmlIsBlank_ch(*p))
white = 0;
else if (*p == 0x20 && !white)
white = 1;
else
ok = 0;
}
if (ok && !white) /* is normalized */
return(NULL);
ret = xmlStrdup(pubID);
q = ret;
white = 0;
for (p = pubID;*p != 0;p++) {
if (xmlIsBlank_ch(*p)) {
if (q != ret)
white = 1;
} else {
if (white) {
*(q++) = 0x20;
white = 0;
}
*(q++) = *p;
}
}
*q = 0;
return(ret);
}
/************************************************************************
* *
* The XML Catalog parser *
......@@ -1858,12 +1922,17 @@ xmlCatalogListXMLResolve(xmlCatalogEntryPtr catal, const xmlChar *pubID,
const xmlChar *sysID) {
xmlChar *ret = NULL;
xmlChar *urnID = NULL;
xmlChar *normid;
if (catal == NULL)
return(NULL);
if ((pubID == NULL) && (sysID == NULL))
return(NULL);
normid = xmlCatalogNormalizePublic(pubID);
if (normid != NULL)
pubID = (*normid != 0 ? normid : NULL);
if (!xmlStrncmp(pubID, BAD_CAST XML_URN_PUBID, sizeof(XML_URN_PUBID) - 1)) {
urnID = xmlCatalogUnWrapURN(pubID);
if (xmlDebugCatalogs) {
......@@ -1877,6 +1946,8 @@ xmlCatalogListXMLResolve(xmlCatalogEntryPtr catal, const xmlChar *pubID,
ret = xmlCatalogListXMLResolve(catal, urnID, sysID);
if (urnID != NULL)
xmlFree(urnID);
if (normid != NULL)
xmlFree(normid);
return(ret);
}
if (!xmlStrncmp(sysID, BAD_CAST XML_URN_PUBID, sizeof(XML_URN_PUBID) - 1)) {
......@@ -1898,6 +1969,8 @@ xmlCatalogListXMLResolve(xmlCatalogEntryPtr catal, const xmlChar *pubID,
}
if (urnID != NULL)
xmlFree(urnID);
if (normid != NULL)
xmlFree(normid);
return(ret);
}
while (catal != NULL) {
......@@ -1907,12 +1980,17 @@ xmlCatalogListXMLResolve(xmlCatalogEntryPtr catal, const xmlChar *pubID,
}
if (catal->children != NULL) {
ret = xmlCatalogXMLResolve(catal->children, pubID, sysID);
if (ret != NULL)
if (ret != NULL) {
if (normid != NULL)
xmlFree(normid);
return(ret);
}
}
}
catal = catal->next;
}
if (normid != NULL)
xmlFree(normid);
return(ret);
}
......@@ -2143,8 +2221,6 @@ xmlGetSGMLCatalogEntryType(const xmlChar *name) {
type = SGML_CATA_CATALOG;
else if (xmlStrEqual(name, (const xmlChar *) "BASE"))
type = SGML_CATA_BASE;
else if (xmlStrEqual(name, (const xmlChar *) "DELEGATE"))
type = SGML_CATA_DELEGATE;
return(type);
}
......@@ -2219,8 +2295,6 @@ xmlParseSGMLCatalog(xmlCatalogPtr catal, const xmlChar *value,
type = SGML_CATA_CATALOG;
else if (xmlStrEqual(name, (const xmlChar *) "BASE"))
type = SGML_CATA_BASE;
else if (xmlStrEqual(name, (const xmlChar *) "DELEGATE"))
type = SGML_CATA_DELEGATE;
else if (xmlStrEqual(name, (const xmlChar *) "OVERRIDE")) {
xmlFree(name);
cur = xmlParseSGMLCatalogName(cur, &name);
......@@ -2266,6 +2340,21 @@ xmlParseSGMLCatalog(xmlCatalogPtr catal, const xmlChar *value,
/* error */
break;
}
if (type != SGML_CATA_SYSTEM) {
xmlChar *normid;
normid = xmlCatalogNormalizePublic(name);
if (normid != NULL) {
if (name != NULL)
xmlFree(name);
if (*normid != 0)
name = normid;
else {
xmlFree(normid);
name = NULL;
}
}
}
if (!IS_BLANK_CH(*cur)) {
/* error */
break;
......@@ -2371,15 +2460,28 @@ xmlParseSGMLCatalog(xmlCatalogPtr catal, const xmlChar *value,
static const xmlChar *
xmlCatalogGetSGMLPublic(xmlHashTablePtr catal, const xmlChar *pubID) {
xmlCatalogEntryPtr entry;
xmlChar *normid;
if (catal == NULL)
return(NULL);
normid = xmlCatalogNormalizePublic(pubID);
if (normid != NULL)
pubID = (*normid != 0 ? normid : NULL);
entry = (xmlCatalogEntryPtr) xmlHashLookup(catal, pubID);
if (entry == NULL)
if (entry == NULL) {
if (normid != NULL)
xmlFree(normid);
return(NULL);
if (entry->type == SGML_CATA_PUBLIC)
}
if (entry->type == SGML_CATA_PUBLIC) {
if (normid != NULL)
xmlFree(normid);
return(entry->URL);
}
if (normid != NULL)
xmlFree(normid);
return(NULL);
}
......
> test/catalogs/calstblx.dtd
> test/catalogs/docbook.dtd
> test/catalogs/soextblx.dtd
> test/catalogs/dbgenent.mod
>
\ No newline at end of file
> /usr/share/xml/docbook/xml/4.1.2/dbpoolx.mod
> http://www.oasis-open.org/docbook/xml/4.1.2/dbcentx.mod
> http://www.oasis-open.org/docbook/xml/4.1.2/dbcentx.mod
> http://www.oasis-open.org/docbook/xml/4.1.2/dbcentx.mod
> http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd
> http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd
> file:///usr/share/xml/toto/toto.dtd
>
\ No newline at end of file
public "-//OASIS//DTD DocBook XML CALS Table Model V4.1//EN "
public "-//Davenport//DTD DocBook V3.0//EN"
public " -//OASIS//DTD XML Exchange Table Model 19990315//EN"
public "-//Davenport//ENTITIES DocBook Additional General Entities V3.0//EN"
PUBLIC " -//OASIS//DTD DocBook XML CALS Table Model V4.1//EN" "calstblx.dtd"
PUBLIC "-//OASIS//DTD XML Exchange Table Model 19990315//EN " "soextblx.dtd"
PUBLIC "-//Davenport//DTD DocBook
V3.0//EN" "docbook.dtd"
PUBLIC "-//Davenport//ENTITIES DocBook Additional General Entities V3.0//EN" "dbgenent.mod"
resolve "toto " http://www.oasis-open.org/docbook/xml/4.1.2/dbpoolx.mod
public "-//OASIS//ENTITIES DocBook XML Character Entities V4.1.2//EN"
public " -//OASIS//ENTITIES DocBook XML Character Entities V4.1.2//EN"
public "-//OASIS//ENTITIES DocBook XML Character Entities V4.1.2//EN "
system urn:publicid:+-:OASIS:DTD+++DocBook+XML+V4.1.2:EN+
public urn:publicid:+-:OASIS:DTD+DocBook+XML+++V4.1.2:EN+
resolve " toto " toto
<?xml version="1.0"?>
<!DOCTYPE catalog PUBLIC "-//OASIS//DTD Entity Resolution XML Catalog V1.0//EN" "http://www.oasis-open.org/committees/entity/release/1.0/catalog.dtd">
<catalog xmlns="urn:oasis:names:tc:entity:xmlns:xml:catalog">
<public publicId="-//OASIS//DTD DocBook XML V4.1.2//EN" uri="http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd"/>
<public publicId="-//OASIS//ENTITIES DocBook XML Notations V4.1.2//EN" uri="http://www.oasis-open.org/docbook/xml/4.1.2/dbnotnx.mod"/>
<public publicId=" -//OASIS//ENTITIES DocBook
XML Character Entities V4.1.2//EN " uri="http://www.oasis-open.org/docbook/xml/4.1.2/dbcentx.mod"/>
<public publicId="-//OASIS//ELEMENTS DocBook XML Information Pool V4.1.2//EN" uri="http://www.oasis-open.org/docbook/xml/4.1.2/dbpoolx.mod"/>
<public publicId="-//OASIS//ELEMENTS DocBook XML Document Hierarchy V4.1.2//EN" uri="http://www.oasis-open.org/docbook/xml/4.1.2/dbhierx.mod"/>
<public publicId="-//OASIS//ENTITIES DocBook XML Additional General Entities V4.1.2//EN" uri="http://www.oasis-open.org/docbook/xml/4.1.2/dbgenent.mod"/>
<public publicId="-//OASIS//DTD DocBook XML CALS Table Model V4.1.2//EN" uri="http://www.oasis-open.org/docbook/xml/4.1.2/calstblx.dtd"/>
<public publicId="-//OASIS//DTD DocBook MathML Module V1.0//EN" uri="http://www.oasis-open.org/docbook/xml/mathml/1.0/dbmathml.dtd"/>
<nextCatalog catalog="stylesheet.xml"/>
<rewriteSystem systemIdStartString="http://www.oasis-open.org/docbook/" rewritePrefix="/usr/share/xml/docbook/"/>
</catalog>
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment