Skip to content

Commit

Permalink
applied patches from Peter Breitenlohner to fix handling of white space
Browse files Browse the repository at this point in the history
* 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
  • Loading branch information
Daniel Veillard committed Jul 16, 2004
1 parent e15df58 commit c815505
Show file tree
Hide file tree
Showing 8 changed files with 159 additions and 7 deletions.
6 changes: 6 additions & 0 deletions ChangeLog
@@ -1,3 +1,9 @@
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
Expand Down
116 changes: 109 additions & 7 deletions catalog.c
Expand Up @@ -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);

/************************************************************************
Expand Down Expand Up @@ -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) {
Expand All @@ -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
Expand Down Expand Up @@ -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 *
Expand Down Expand Up @@ -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) {
Expand All @@ -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)) {
Expand All @@ -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) {
Expand All @@ -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);
}

Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}

Expand Down
5 changes: 5 additions & 0 deletions result/catalogs/whites
@@ -0,0 +1,5 @@
> test/catalogs/calstblx.dtd
> test/catalogs/docbook.dtd
> test/catalogs/soextblx.dtd
> test/catalogs/dbgenent.mod
>
8 changes: 8 additions & 0 deletions result/catalogs/whitex
@@ -0,0 +1,8 @@
> /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
>
4 changes: 4 additions & 0 deletions test/catalogs/whites.script
@@ -0,0 +1,4 @@
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"
5 changes: 5 additions & 0 deletions test/catalogs/whites.sgml
@@ -0,0 +1,5 @@
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"
7 changes: 7 additions & 0 deletions test/catalogs/whitex.script
@@ -0,0 +1,7 @@
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
15 changes: 15 additions & 0 deletions test/catalogs/whitex.xml
@@ -0,0 +1,15 @@
<?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>

0 comments on commit c815505

Please sign in to comment.