Re: Python improvements to expat
Michael Gilbert <[email protected]> Mon, 18 Jan 2010 12:28:35 -0500
| Newsgroups | gmane.text.xml.expat.general |
|---|---|
| Message-ID | <[email protected]> |
Hi, Mozilla has made some real changes to expat. Would it make sense to merge any of their modifications? See the attached diff. Best wishes, Mike _______________________________________________ Expat-discuss mailing list [email protected] http://mail.libexpat.org/mailman/listinfo/expat-discuss
expat-mozilla.diff
(text/x-diff, 16.7 KB)
Only in expat-2.0.0/lib/: amigaconfig.h
Only in expat-2.0.0/lib/: expat.dsp
diff -ur expat-2.0.0/lib/expat_external.h xulrunner-1.9.1.6/parser/expat/lib/expat_external.h
--- expat-2.0.0/lib/expat_external.h 2005-12-28 01:07:52.000000000 -0500
+++ xulrunner-1.9.1.6/parser/expat/lib/expat_external.h 2009-12-01 23:28:52.000000000 -0500
@@ -82,6 +82,9 @@
#define XML_UNICODE
#endif
+/* BEGIN MOZILLA CHANGE (typedef XML_Char to PRUnichar) */
+#if 0
+
#ifdef XML_UNICODE /* Information is UTF-16 encoded. */
#ifdef XML_UNICODE_WCHAR_T
typedef wchar_t XML_Char;
@@ -95,6 +98,9 @@
typedef char XML_LChar;
#endif /* XML_UNICODE */
+#endif
+/* END MOZILLA CHANGE */
+
#ifdef XML_LARGE_SIZE /* Use large integers for file/stream positions. */
#if defined(XML_USE_MSC_EXTENSIONS) && _MSC_VER < 1400
typedef __int64 XML_Index;
diff -ur expat-2.0.0/lib/expat.h xulrunner-1.9.1.6/parser/expat/lib/expat.h
--- expat-2.0.0/lib/expat.h 2005-12-26 10:43:22.000000000 -0500
+++ xulrunner-1.9.1.6/parser/expat/lib/expat.h 2009-12-01 23:28:52.000000000 -0500
@@ -1006,6 +1006,11 @@
#define XML_MINOR_VERSION 0
#define XML_MICRO_VERSION 0
+/* BEGIN MOZILLA CHANGE (Report opening tag of mismatched closing tag) */
+XMLPARSEAPI(const XML_Char*)
+MOZ_XML_GetMismatchedTag(XML_Parser parser);
+/* END MOZILLA CHANGE */
+
#ifdef __cplusplus
}
#endif
Only in expat-2.0.0/lib/: expat_static.dsp
Only in expat-2.0.0/lib/: expatw.dsp
Only in expat-2.0.0/lib/: expatw_static.dsp
Only in expat-2.0.0/lib/: libexpat.def
Only in expat-2.0.0/lib/: libexpatw.def
Only in expat-2.0.0/lib/: macconfig.h
Only in xulrunner-1.9.1.6/parser/expat/lib/: Makefile.in
Only in expat-2.0.0/lib/: Makefile.MPW
Only in xulrunner-1.9.1.6/parser/expat/lib/: moz_extensions.c
Only in expat-2.0.0/lib/: winconfig.h
diff -ur expat-2.0.0/lib/xmlparse.c xulrunner-1.9.1.6/parser/expat/lib/xmlparse.c
--- expat-2.0.0/lib/xmlparse.c 2005-12-23 09:45:27.000000000 -0500
+++ xulrunner-1.9.1.6/parser/expat/lib/xmlparse.c 2009-12-01 23:28:52.000000000 -0500
@@ -49,6 +49,9 @@
#endif
+/* BEGIN MOZILLA CHANGE (typedef XML_Char to PRUnichar) */
+#if 0
+
#ifdef XML_UNICODE
#ifdef XML_UNICODE_WCHAR_T
@@ -66,6 +69,9 @@
#endif
+#endif
+/* END MOZILLA CHANGE */
+
/* Round up n to be a multiple of sz, where sz is a power of 2. */
#define ROUND_UP(n, sz) (((n) + ((sz) - 1)) & ~((sz) - 1))
@@ -542,6 +548,9 @@
XML_Bool m_useForeignDTD;
enum XML_ParamEntityParsing m_paramEntityParsing;
#endif
+/* BEGIN MOZILLA CHANGE (Report opening tag of mismatched closing tag) */
+ const XML_Char* m_mismatch;
+/* END MOZILLA CHANGE */
};
#define MALLOC(s) (parser->m_mem.malloc_fcn((s)))
@@ -649,13 +658,20 @@
#define useForeignDTD (parser->m_useForeignDTD)
#define paramEntityParsing (parser->m_paramEntityParsing)
#endif /* XML_DTD */
+/* BEGIN MOZILLA CHANGE (Report opening tag of mismatched closing tag) */
+#define mismatch (parser->m_mismatch)
+/* END MOZILLA CHANGE */
+/* BEGIN MOZILLA CHANGE (unused API) */
+#ifdef TX_EXE
XML_Parser XMLCALL
XML_ParserCreate(const XML_Char *encodingName)
{
return XML_ParserCreate_MM(encodingName, NULL, NULL);
}
+#endif
+#if 0
XML_Parser XMLCALL
XML_ParserCreateNS(const XML_Char *encodingName, XML_Char nsSep)
{
@@ -663,6 +679,8 @@
*tmp = nsSep;
return XML_ParserCreate_MM(encodingName, NULL, tmp);
}
+#endif
+/* END MOZILLA CHANGE */
static const XML_Char implicitContext[] = {
'x', 'm', 'l', '=', 'h', 't', 't', 'p', ':', '/', '/',
@@ -787,6 +805,10 @@
internalEncoding = XmlGetInternalEncoding();
}
+/* BEGIN MOZILLA CHANGE (Report opening tag of mismatched closing tag) */
+ mismatch = NULL;
+/* END MOZILLA CHANGE */
+
return parser;
}
@@ -874,6 +896,8 @@
}
}
+/* BEGIN MOZILLA CHANGE (unused API) */
+#if 0
XML_Bool XMLCALL
XML_ParserReset(XML_Parser parser, const XML_Char *encodingName)
{
@@ -928,6 +952,8 @@
}
return XML_STATUS_OK;
}
+#endif
+/* END MOZILLA CHANGE */
XML_Parser XMLCALL
XML_ExternalEntityParserCreate(XML_Parser oldParser,
@@ -1140,6 +1166,8 @@
handlerArg = parser;
}
+/* BEGIN MOZILLA CHANGE (unused API) */
+#if 0
enum XML_Error XMLCALL
XML_UseForeignDTD(XML_Parser parser, XML_Bool useDTD)
{
@@ -1153,6 +1181,8 @@
return XML_ERROR_FEATURE_REQUIRES_XML_DTD;
#endif
}
+#endif
+/* END MOZILLA CHANGE */
void XMLCALL
XML_SetReturnNSTriplet(XML_Parser parser, int do_nst)
@@ -1213,6 +1243,8 @@
endElementHandler = end;
}
+/* BEGIN MOZILLA CHANGE (unused API) */
+#if 0
void XMLCALL
XML_SetStartElementHandler(XML_Parser parser,
XML_StartElementHandler start) {
@@ -1224,6 +1256,8 @@
XML_EndElementHandler end) {
endElementHandler = end;
}
+#endif
+/* END MOZILLA CHANGE */
void XMLCALL
XML_SetCharacterDataHandler(XML_Parser parser,
@@ -1255,6 +1289,8 @@
endCdataSectionHandler = end;
}
+/* BEGIN MOZILLA CHANGE (unused API) */
+#if 0
void XMLCALL
XML_SetStartCdataSectionHandler(XML_Parser parser,
XML_StartCdataSectionHandler start) {
@@ -1274,6 +1310,8 @@
defaultHandler = handler;
defaultExpandInternalEntities = XML_FALSE;
}
+#endif
+/* END MOZILLA CHANGE */
void XMLCALL
XML_SetDefaultHandlerExpand(XML_Parser parser,
@@ -1292,6 +1330,8 @@
endDoctypeDeclHandler = end;
}
+/* BEGIN MOZILLA CHANGE (unused API) */
+#if 0
void XMLCALL
XML_SetStartDoctypeDeclHandler(XML_Parser parser,
XML_StartDoctypeDeclHandler start) {
@@ -1303,6 +1343,8 @@
XML_EndDoctypeDeclHandler end) {
endDoctypeDeclHandler = end;
}
+#endif
+/* END MOZILLA CHANGE */
void XMLCALL
XML_SetUnparsedEntityDeclHandler(XML_Parser parser,
@@ -1327,6 +1369,9 @@
endNamespaceDeclHandler = end;
}
+
+/* BEGIN MOZILLA CHANGE (unused API) */
+#if 0
void XMLCALL
XML_SetStartNamespaceDeclHandler(XML_Parser parser,
XML_StartNamespaceDeclHandler start) {
@@ -1345,6 +1390,8 @@
{
notStandaloneHandler = handler;
}
+#endif
+/* END MOZILLA CHANGE */
void XMLCALL
XML_SetExternalEntityRefHandler(XML_Parser parser,
@@ -1362,6 +1409,8 @@
externalEntityRefHandlerArg = parser;
}
+/* BEGIN MOZILLA CHANGE (unused API) */
+#if 0
void XMLCALL
XML_SetSkippedEntityHandler(XML_Parser parser,
XML_SkippedEntityHandler handler)
@@ -1398,6 +1447,8 @@
{
entityDeclHandler = handler;
}
+#endif
+/* END MOZILLA CHANGE */
void XMLCALL
XML_SetXmlDeclHandler(XML_Parser parser,
@@ -1735,6 +1786,10 @@
XmlUpdatePosition(encoding, positionPtr, bufferPtr, &position);
positionPtr = bufferPtr;
+/* BEGIN MOZILLA CHANGE (always set eventPtr/eventEndPtr) */
+ eventPtr = bufferPtr;
+ eventEndPtr = bufferPtr;
+/* END MOZILLA CHANGE */
return result;
}
@@ -1756,9 +1811,17 @@
{
if (eventPtr)
return parseEndByteIndex - (parseEndPtr - eventPtr);
+/* BEGIN MOZILLA CHANGE (fix XML_GetCurrentByteIndex) */
+#if 0
return -1;
+#else
+ return parseEndByteIndex;
+#endif
+/* END MOZILLA CHANGE */
}
+/* BEGIN MOZILLA CHANGE (unused API) */
+#if 0
int XMLCALL
XML_GetCurrentByteCount(XML_Parser parser)
{
@@ -1779,6 +1842,8 @@
#endif /* defined XML_CONTEXT_BYTES */
return (char *) 0;
}
+#endif
+/* END MOZILLA CHANGE */
XML_Size XMLCALL
XML_GetCurrentLineNumber(XML_Parser parser)
@@ -1800,6 +1865,8 @@
return position.columnNumber;
}
+/* BEGIN MOZILLA CHANGE (unused API) */
+#if 0
void XMLCALL
XML_FreeContentModel(XML_Parser parser, XML_Content *model)
{
@@ -1837,7 +1904,9 @@
reportDefault(parser, encoding, eventPtr, eventEndPtr);
}
}
+#endif
+#ifdef TX_EXE
const XML_LChar * XMLCALL
XML_ErrorString(enum XML_Error code)
{
@@ -1888,7 +1957,9 @@
return message[code];
return NULL;
}
+#endif
+#if 0
const XML_LChar * XMLCALL
XML_ExpatVersion(void) {
@@ -1953,6 +2024,16 @@
return features;
}
+#endif
+/* END MOZILLA CHANGE */
+
+/* BEGIN MOZILLA CHANGE (Report opening tag of mismatched closing tag) */
+const XML_Char * XMLCALL
+MOZ_XML_GetMismatchedTag(XML_Parser parser)
+{
+ return mismatch;
+}
+/* END MOZILLA CHANGE */
/* Initially tag->rawName always points into the parse buffer;
for those TAG instances opened while the current parse buffer was
@@ -2246,9 +2327,15 @@
else if (!entity) {
if (skippedEntityHandler)
skippedEntityHandler(handlerArg, name, 0);
+/* BEGIN MOZILLA CHANGE (http://bugzilla.mozilla.org/show_bug.cgi?id=35984) */
+#if 0
else if (defaultHandler)
reportDefault(parser, enc, s, next);
break;
+#else
+ return XML_ERROR_UNDEFINED_ENTITY;
+#endif
+/* END MOZILLA CHANGE */
}
if (entity->open)
return XML_ERROR_RECURSIVE_ENTITY_REF;
@@ -2413,6 +2500,29 @@
len = XmlNameLength(enc, rawName);
if (len != tag->rawNameLength
|| memcmp(tag->rawName, rawName, len) != 0) {
+/* BEGIN MOZILLA CHANGE (Report opening tag of mismatched closing tag) */
+ /* This code is copied from the |if (endElementHandler)| block below */
+ const XML_Char *localPart;
+ const XML_Char *prefix;
+ XML_Char *uri;
+ localPart = tag->name.localPart;
+ if (ns && localPart) {
+ /* localPart and prefix may have been overwritten in
+ tag->name.str, since this points to the binding->uri
+ buffer which gets re-used; so we have to add them again
+ */
+ uri = (XML_Char *)tag->name.str + tag->name.uriLen;
+ /* don't need to check for space - already done in storeAtts() */
+ while (*localPart) *uri++ = *localPart++;
+ prefix = (XML_Char *)tag->name.prefix;
+ if (ns_triplets && prefix) {
+ *uri++ = namespaceSeparator;
+ while (*prefix) *uri++ = *prefix++;
+ }
+ *uri = XML_T('\0');
+ }
+ mismatch = tag->name.str;
+/* END MOZILLA CHANGE */
*eventPP = rawName;
return XML_ERROR_TAG_MISMATCH;
}
@@ -2614,6 +2724,9 @@
int n;
XML_Char *uri;
int nPrefixes = 0;
+/* BEGIN MOZILLA CHANGE (Include xmlns attributes in attributes array) */
+ int nXMLNSDeclarations = 0;
+/* END MOZILLA CHANGE */
BINDING *binding;
const XML_Char *localPart;
@@ -2705,7 +2818,15 @@
appAtts[attIndex], bindingsPtr);
if (result)
return result;
+/* BEGIN MOZILLA CHANGE (Include xmlns attributes in attributes array) */
+#if 0
--attIndex;
+#else
+ attIndex++;
+ nXMLNSDeclarations++;
+ (attId->name)[-1] = 3;
+#endif
+/* END MOZILLA CHANGE */
}
else {
/* deal with other prefixed names later */
@@ -2740,6 +2861,12 @@
da->value, bindingsPtr);
if (result)
return result;
+/* BEGIN MOZILLA CHANGE (Include xmlns attributes in attributes array) */
+ (da->id->name)[-1] = 3;
+ nXMLNSDeclarations++;
+ appAtts[attIndex++] = da->id->name;
+ appAtts[attIndex++] = da->value;
+/* END MOZILLA CHANGE */
}
else {
(da->id->name)[-1] = 2;
@@ -2760,10 +2887,19 @@
/* expand prefixed attribute names, check for duplicates,
and clear flags that say whether attributes were specified */
i = 0;
+/* BEGIN MOZILLA CHANGE (Include xmlns attributes in attributes array) */
+#if 0
if (nPrefixes) {
+#else
+ if (nPrefixes || nXMLNSDeclarations) {
+#endif
+/* END MOZILLA CHANGE */
int j; /* hash table index */
unsigned long version = nsAttsVersion;
int nsAttsSize = (int)1 << nsAttsPower;
+/* BEGIN MOZILLA CHANGE (Include xmlns attributes in attributes array) */
+ if (nPrefixes) {
+/* END MOZILLA CHANGE */
/* size of hash table must be at least 2 * (# of prefixed attributes) */
if ((nPrefixes << 1) >> nsAttsPower) { /* true for nsAttsPower = 0 */
NS_ATT *temp;
@@ -2785,6 +2921,9 @@
nsAtts[--j].version = version;
}
nsAttsVersion = --version;
+/* BEGIN MOZILLA CHANGE (Include xmlns attributes in attributes array) */
+ }
+/* END MOZILLA CHANGE */
/* expand prefixed names and check for duplicates */
for (; i < attIndex; i += 2) {
@@ -2856,11 +2995,65 @@
nsAtts[j].hash = uriHash;
nsAtts[j].uriName = s;
- if (!--nPrefixes) {
+/* BEGIN MOZILLA CHANGE (Include xmlns attributes in attributes array) */
+#if 0
+ if (!--nPrefixes)
+#else
+ if (!--nPrefixes && !nXMLNSDeclarations) {
+#endif
+/* END MOZILLA CHANGE */
+ i += 2;
+ break;
+ }
+ }
+/* BEGIN MOZILLA CHANGE (Include xmlns attributes in attributes array) */
+ else if (s[-1] == 3) { /* xmlns attribute */
+ static const XML_Char xmlnsNamespace[] = {
+ 'h', 't', 't', 'p', ':', '/', '/',
+ 'w', 'w', 'w', '.', 'w', '3', '.', 'o', 'r', 'g', '/',
+ '2', '0', '0', '0', '/', 'x', 'm', 'l', 'n', 's', '/', '\0'
+ };
+ static const XML_Char xmlnsPrefix[] = {
+ 'x', 'm', 'l', 'n', 's', '\0'
+ };
+ XML_Bool appendXMLNS = XML_TRUE;
+
+ ((XML_Char *)s)[-1] = 0; /* clear flag */
+ if (!poolAppendString(&tempPool, xmlnsNamespace)
+ || !poolAppendChar(&tempPool, namespaceSeparator))
+ return XML_ERROR_NO_MEMORY;
+ s += sizeof(xmlnsPrefix) / sizeof(xmlnsPrefix[0]) - 1;
+ if (*s == XML_T(':')) {
+ ++s;
+ do { /* copies null terminator */
+ if (!poolAppendChar(&tempPool, *s))
+ return XML_ERROR_NO_MEMORY;
+ } while (*s++);
+ if (ns_triplets) { /* append namespace separator and prefix */
+ tempPool.ptr[-1] = namespaceSeparator;
+ if (!poolAppendString(&tempPool, xmlnsPrefix)
+ || !poolAppendChar(&tempPool, '\0'))
+ return XML_ERROR_NO_MEMORY;
+ }
+ }
+ else {
+ /* xlmns attribute without a prefix. */
+ if (!poolAppendString(&tempPool, xmlnsPrefix)
+ || !poolAppendChar(&tempPool, '\0'))
+ return XML_ERROR_NO_MEMORY;
+ }
+
+ /* store expanded name in attribute list */
+ s = poolStart(&tempPool);
+ poolFinish(&tempPool);
+ appAtts[i] = s;
+
+ if (!--nXMLNSDeclarations && !nPrefixes) {
i += 2;
break;
}
}
+/* END MOZILLA CHANGE */
else /* not prefixed */
((XML_Char *)s)[-1] = 0; /* clear flag */
}
@@ -4393,7 +4586,13 @@
dtd->paramEntityRead = XML_FALSE;
entity->open = XML_TRUE;
if (!externalEntityRefHandler(externalEntityRefHandlerArg,
+/* BEGIN MOZILLA CHANGE (http://bugzilla.mozilla.org/show_bug.cgi?id=191482) */
+#if 0
0,
+#else
+ entity->name,
+#endif
+/* END MOZILLA CHANGE */
entity->base,
entity->systemId,
entity->publicId)) {
@@ -4909,7 +5108,13 @@
if ((pool == &tempPool) && defaultHandler)
reportDefault(parser, enc, ptr, next);
*/
+/* BEGIN MOZILLA CHANGE (http://bugzilla.mozilla.org/show_bug.cgi?id=35984) */
+#if 0
break;
+#else
+ return XML_ERROR_UNDEFINED_ENTITY;
+#endif
+/* END MOZILLA CHANGE */
}
if (entity->open) {
if (enc == encoding)
diff -ur expat-2.0.0/lib/xmltok.c xulrunner-1.9.1.6/parser/expat/lib/xmltok.c
--- expat-2.0.0/lib/xmltok.c 2005-02-25 20:38:13.000000000 -0500
+++ xulrunner-1.9.1.6/parser/expat/lib/xmltok.c 2009-12-01 23:28:52.000000000 -0500
@@ -1070,6 +1070,12 @@
ASCII_n, ASCII_o, '\0'
};
+/* BEGIN MOZILLA CHANGE (http://bugzilla.mozilla.org/show_bug.cgi?id=62157) */
+static const char KW_XML_1_0[] = {
+ ASCII_1, ASCII_PERIOD, ASCII_0, '\0'
+};
+/* END MOZILLA CHANGE */
+
static int
doParseXmlDecl(const ENCODING *(*encodingFinder)(const ENCODING *,
const char *,
@@ -1106,6 +1112,13 @@
*versionPtr = val;
if (versionEndPtr)
*versionEndPtr = ptr;
+/* BEGIN MOZILLA CHANGE (http://bugzilla.mozilla.org/show_bug.cgi?id=62157) */
+ /* Anything else but a version="1.0" is invalid for us, until we support later versions. */
+ if (!XmlNameMatchesAscii(enc, val, ptr - enc->minBytesPerChar, KW_XML_1_0)) {
+ *badPtr = val;
+ return 0;
+ }
+/* END MOZILLA CHANGE */
if (!parsePseudoAttribute(enc, ptr, end, &name, &nameEnd, &val, &ptr)) {
*badPtr = ptr;
return 0;
@@ -1637,3 +1650,9 @@
}
#endif /* XML_NS */
+
+/* BEGIN MOZILLA CHANGE (Mozilla extensions for QName checking) */
+#ifdef MOZILLA_CLIENT
+#include "moz_extensions.c"
+#endif /* MOZILLA_CLIENT */
+/* END MOZILLA CHANGE */
moz_extensions.c
(text/x-csrc, 5.4 KB)
/* -*- Mode: C; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*- */ /* ***** BEGIN LICENSE BLOCK ***** * Version: MPL 1.1/GPL 2.0/LGPL 2.1 * * The contents of this file are subject to the Mozilla Public License Version * 1.1 (the "License"); you may not use this file except in compliance with * the License. You may obtain a copy of the License at * http://www.mozilla.org/MPL/ * * Software distributed under the License is distributed on an "AS IS" basis, * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License * for the specific language governing rights and limitations under the * License. * * The Original Code is mozilla.org code. * * The Initial Developer of the Original Code is * Peter Van der Beken. * Portions created by the Initial Developer are Copyright (C) 2004 * the Initial Developer. All Rights Reserved. * * Contributor(s): * Peter Van der Beken <[email protected]> * * * Alternatively, the contents of this file may be used under the terms of * either the GNU General Public License Version 2 or later (the "GPL"), or * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"), * in which case the provisions of the GPL or the LGPL are applicable instead * of those above. If you wish to allow use of your version of this file only * under the terms of either the GPL or the LGPL, and not to allow others to * use your version of this file under the terms of the MPL, indicate your * decision by deleting the provisions above and replace them with the notice * and other provisions required by the GPL or the LGPL. If you do not delete * the provisions above, a recipient may use your version of this file under * the terms of any one of the MPL, the GPL or the LGPL. * * ***** END LICENSE BLOCK ***** */ #ifdef IS_LITTLE_ENDIAN #define PREFIX(ident) little2_ ## ident #define BYTE_TYPE(p) LITTLE2_BYTE_TYPE(XmlGetUtf16InternalEncodingNS(), p) #define IS_NAME_CHAR_MINBPC(p) LITTLE2_IS_NAME_CHAR_MINBPC(0, p) #define IS_NMSTRT_CHAR_MINBPC(p) LITTLE2_IS_NMSTRT_CHAR_MINBPC(0, p) #else #define PREFIX(ident) big2_ ## ident #define BYTE_TYPE(p) BIG2_BYTE_TYPE(XmlGetUtf16InternalEncodingNS(), p) #define IS_NAME_CHAR_MINBPC(p) BIG2_IS_NAME_CHAR_MINBPC(0, p) #define IS_NMSTRT_CHAR_MINBPC(p) BIG2_IS_NMSTRT_CHAR_MINBPC(0, p) #endif #define MOZ_EXPAT_VALID_QNAME (0) #define MOZ_EXPAT_EMPTY_QNAME (1 << 0) #define MOZ_EXPAT_INVALID_CHARACTER (1 << 1) #define MOZ_EXPAT_MALFORMED (1 << 2) int MOZ_XMLCheckQName(const char* ptr, const char* end, int ns_aware, const char** colon) { int result = MOZ_EXPAT_VALID_QNAME; int nmstrt = 1; *colon = 0; if (ptr == end) { return MOZ_EXPAT_EMPTY_QNAME; } do { switch (BYTE_TYPE(ptr)) { case BT_COLON: /* We're namespace-aware and either first or last character is a colon or we've already seen a colon. */ if (ns_aware && (nmstrt || *colon || ptr + 2 == end)) { return MOZ_EXPAT_MALFORMED; } *colon = ptr; nmstrt = ns_aware; /* e.g. "a:0" should be valid if !ns_aware */ break; case BT_NONASCII: if (nmstrt && !IS_NMSTRT_CHAR_MINBPC(ptr)) { /* If this is a valid name character and we're namespace-aware, the QName is malformed. Otherwise, this character's invalid at the start of a name (or, if we're namespace-aware, at the start of a localpart). */ return (IS_NAME_CHAR_MINBPC(ptr) && ns_aware) ? MOZ_EXPAT_MALFORMED : MOZ_EXPAT_INVALID_CHARACTER; } if (!IS_NAME_CHAR_MINBPC(ptr)) { return MOZ_EXPAT_INVALID_CHARACTER; } nmstrt = 0; break; case BT_NMSTRT: case BT_HEX: nmstrt = 0; break; case BT_DIGIT: case BT_NAME: case BT_MINUS: if (nmstrt) { return MOZ_EXPAT_INVALID_CHARACTER; } break; default: return MOZ_EXPAT_INVALID_CHARACTER; } ptr += 2; } while (ptr != end); return result; } int MOZ_XMLIsLetter(const char* ptr) { switch (BYTE_TYPE(ptr)) { case BT_NONASCII: if (!IS_NMSTRT_CHAR_MINBPC(ptr)) { return 0; } case BT_NMSTRT: case BT_HEX: return 1; default: return 0; } } int MOZ_XMLIsNCNameChar(const char* ptr) { switch (BYTE_TYPE(ptr)) { case BT_NONASCII: if (!IS_NAME_CHAR_MINBPC(ptr)) { return 0; } case BT_NMSTRT: case BT_HEX: case BT_DIGIT: case BT_NAME: case BT_MINUS: return 1; default: return 0; } } int MOZ_XMLTranslateEntity(const char* ptr, const char* end, const char** next, XML_Char* result) { const ENCODING* enc = XmlGetUtf16InternalEncodingNS(); int tok = PREFIX(scanRef)(enc, ptr, end, next); if (tok <= XML_TOK_INVALID) { return 0; } if (tok == XML_TOK_CHAR_REF) { int n = XmlCharRefNumber(enc, ptr); /* We could get away with just < 0, but better safe than sorry. */ if (n <= 0) { return 0; } return XmlUtf16Encode(n, (unsigned short*)result); } if (tok == XML_TOK_ENTITY_REF) { /* *next points to after the semicolon, so the entity ends at *next - enc->minBytesPerChar. */ XML_Char ch = (XML_Char)XmlPredefinedEntityName(enc, ptr, *next - enc->minBytesPerChar); if (!ch) { return 0; } *result = ch; return 1; } return 0; } #undef PREFIX #undef BYTE_TYPE #undef IS_NAME_CHAR_MINBPC #undef IS_NMSTRT_CHAR_MINBPC