Permalink
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
  • Loading branch information...
1 parent e15df58 commit c815505f7d7a09a834d33aa6fefe10b48be2bfc9 Daniel Veillard committed Jul 16, 2004
Showing with 159 additions and 7 deletions.
  1. +6 −0 ChangeLog
  2. +109 −7 catalog.c
  3. +5 −0 result/catalogs/whites
  4. +8 −0 result/catalogs/whitex
  5. +4 −0 test/catalogs/whites.script
  6. +5 −0 test/catalogs/whites.sgml
  7. +7 −0 test/catalogs/whitex.script
  8. +15 −0 test/catalogs/whitex.xml
View
6 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
View
116 catalog.c
@@ -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);
}
View
5 result/catalogs/whites
@@ -0,0 +1,5 @@
+> test/catalogs/calstblx.dtd
+> test/catalogs/docbook.dtd
+> test/catalogs/soextblx.dtd
+> test/catalogs/dbgenent.mod
+>
View
8 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
+>
View
4 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"
View
5 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"
View
7 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
View
15 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.