Skip to content

Commit 4faea01

Browse files
committed
Update to the final version released as Expat 1.95.6 (maintaining
Martin's integration changes).
1 parent d97da80 commit 4faea01

1 file changed

Lines changed: 66 additions & 78 deletions

File tree

Modules/expat/xmlparse.c

Lines changed: 66 additions & 78 deletions
Original file line numberDiff line numberDiff line change
@@ -309,8 +309,8 @@ doIgnoreSection(XML_Parser parser, const ENCODING *, const char **startPtr,
309309
#endif /* XML_DTD */
310310

311311
static enum XML_Error
312-
storeAtts(XML_Parser parser, const ENCODING *,
313-
const char *s, TAG_NAME *tagNamePtr, BINDING **bindingsPtr);
312+
storeAtts(XML_Parser parser, const ENCODING *, const char *s,
313+
TAG_NAME *tagNamePtr, BINDING **bindingsPtr);
314314
static enum XML_Error
315315
addBinding(XML_Parser parser, PREFIX *prefix, const ATTRIBUTE_ID *attId,
316316
const XML_Char *uri, BINDING **bindingsPtr);
@@ -2097,11 +2097,6 @@ doContent(XML_Parser parser,
20972097
}
20982098
tag->name.str = (XML_Char *)tag->buf;
20992099
*toPtr = XML_T('\0');
2100-
if (!startElementHandler && (tok == XML_TOK_START_TAG_NO_ATTS)) {
2101-
if (defaultHandler)
2102-
reportDefault(parser, enc, s, next);
2103-
break;
2104-
}
21052100
result = storeAtts(parser, enc, s, &(tag->name), &(tag->bindings));
21062101
if (result)
21072102
return result;
@@ -2114,13 +2109,6 @@ doContent(XML_Parser parser,
21142109
break;
21152110
}
21162111
case XML_TOK_EMPTY_ELEMENT_NO_ATTS:
2117-
if (!startElementHandler && !endElementHandler) {
2118-
if (defaultHandler)
2119-
reportDefault(parser, enc, s, next);
2120-
if (tagLevel == 0)
2121-
return epilogProcessor(parser, next, end, nextPtr);
2122-
break;
2123-
}
21242112
/* fall through */
21252113
case XML_TOK_EMPTY_ELEMENT_WITH_ATTS:
21262114
{
@@ -2134,13 +2122,10 @@ doContent(XML_Parser parser,
21342122
if (!name.str)
21352123
return XML_ERROR_NO_MEMORY;
21362124
poolFinish(&tempPool);
2137-
if (startElementHandler ||
2138-
(tok == XML_TOK_EMPTY_ELEMENT_WITH_ATTS)) {
2139-
result = storeAtts(parser, enc, s, &name, &bindings);
2140-
if (result)
2141-
return result;
2142-
poolFinish(&tempPool);
2143-
}
2125+
result = storeAtts(parser, enc, s, &name, &bindings);
2126+
if (result)
2127+
return result;
2128+
poolFinish(&tempPool);
21442129
if (startElementHandler) {
21452130
startElementHandler(handlerArg, name.str, (const XML_Char **)atts);
21462131
noElmHandlers = XML_FALSE;
@@ -2343,8 +2328,15 @@ doContent(XML_Parser parser,
23432328
/* not reached */
23442329
}
23452330

2346-
/* If tagNamePtr is non-null, build a real list of attributes,
2347-
otherwise just check the attributes for well-formedness.
2331+
/* Precondition: all arguments must be non-NULL;
2332+
Purpose:
2333+
- normalize attributes
2334+
- check attributes for well-formedness
2335+
- generate namespace aware attribute names (URI, prefix)
2336+
- build list of attributes for startElementHandler
2337+
- default attributes
2338+
- process namespace declarations (check and report them)
2339+
- generate namespace aware element name (URI, prefix)
23482340
*/
23492341
static enum XML_Error
23502342
storeAtts(XML_Parser parser, const ENCODING *enc,
@@ -2365,21 +2357,20 @@ storeAtts(XML_Parser parser, const ENCODING *enc,
23652357
const XML_Char *localPart;
23662358

23672359
/* lookup the element type name */
2368-
if (tagNamePtr) {
2369-
elementType = (ELEMENT_TYPE *)lookup(&dtd->elementTypes, tagNamePtr->str,0);
2370-
if (!elementType) {
2371-
const XML_Char *name = poolCopyString(&dtd->pool, tagNamePtr->str);
2372-
if (!name)
2373-
return XML_ERROR_NO_MEMORY;
2374-
elementType = (ELEMENT_TYPE *)lookup(&dtd->elementTypes, name,
2375-
sizeof(ELEMENT_TYPE));
2376-
if (!elementType)
2377-
return XML_ERROR_NO_MEMORY;
2378-
if (ns && !setElementTypePrefix(parser, elementType))
2379-
return XML_ERROR_NO_MEMORY;
2380-
}
2381-
nDefaultAtts = elementType->nDefaultAtts;
2360+
elementType = (ELEMENT_TYPE *)lookup(&dtd->elementTypes, tagNamePtr->str,0);
2361+
if (!elementType) {
2362+
const XML_Char *name = poolCopyString(&dtd->pool, tagNamePtr->str);
2363+
if (!name)
2364+
return XML_ERROR_NO_MEMORY;
2365+
elementType = (ELEMENT_TYPE *)lookup(&dtd->elementTypes, name,
2366+
sizeof(ELEMENT_TYPE));
2367+
if (!elementType)
2368+
return XML_ERROR_NO_MEMORY;
2369+
if (ns && !setElementTypePrefix(parser, elementType))
2370+
return XML_ERROR_NO_MEMORY;
23822371
}
2372+
nDefaultAtts = elementType->nDefaultAtts;
2373+
23832374
/* get the attributes from the tokenizer */
23842375
n = XmlGetAttributes(enc, attStr, attsSize, atts);
23852376
if (n + nDefaultAtts > attsSize) {
@@ -2393,6 +2384,7 @@ storeAtts(XML_Parser parser, const ENCODING *enc,
23932384
if (n > oldAttsSize)
23942385
XmlGetAttributes(enc, attStr, n, atts);
23952386
}
2387+
23962388
appAtts = (const XML_Char **)atts;
23972389
for (i = 0; i < n; i++) {
23982390
/* add the name and value to the attribute list */
@@ -2430,14 +2422,10 @@ storeAtts(XML_Parser parser, const ENCODING *enc,
24302422
&tempPool);
24312423
if (result)
24322424
return result;
2433-
if (tagNamePtr) {
2434-
appAtts[attIndex] = poolStart(&tempPool);
2435-
poolFinish(&tempPool);
2436-
}
2437-
else
2438-
poolDiscard(&tempPool);
2425+
appAtts[attIndex] = poolStart(&tempPool);
2426+
poolFinish(&tempPool);
24392427
}
2440-
else if (tagNamePtr) {
2428+
else {
24412429
/* the value did not need normalizing */
24422430
appAtts[attIndex] = poolStoreString(&tempPool, enc, atts[i].valuePtr,
24432431
atts[i].valueEnd);
@@ -2446,7 +2434,7 @@ storeAtts(XML_Parser parser, const ENCODING *enc,
24462434
poolFinish(&tempPool);
24472435
}
24482436
/* handle prefixed attribute names */
2449-
if (attId->prefix && tagNamePtr) {
2437+
if (attId->prefix) {
24502438
if (attId->xmlns) {
24512439
/* deal with namespace declarations here */
24522440
enum XML_Error result = addBinding(parser, attId->prefix, attId,
@@ -2465,45 +2453,46 @@ storeAtts(XML_Parser parser, const ENCODING *enc,
24652453
else
24662454
attIndex++;
24672455
}
2468-
if (tagNamePtr) {
2469-
int j;
2470-
nSpecifiedAtts = attIndex;
2471-
if (elementType->idAtt && (elementType->idAtt->name)[-1]) {
2472-
for (i = 0; i < attIndex; i += 2)
2473-
if (appAtts[i] == elementType->idAtt->name) {
2474-
idAttIndex = i;
2475-
break;
2476-
}
2477-
}
2478-
else
2479-
idAttIndex = -1;
2480-
/* do attribute defaulting */
2481-
for (j = 0; j < nDefaultAtts; j++) {
2482-
const DEFAULT_ATTRIBUTE *da = elementType->defaultAtts + j;
2483-
if (!(da->id->name)[-1] && da->value) {
2484-
if (da->id->prefix) {
2485-
if (da->id->xmlns) {
2486-
enum XML_Error result = addBinding(parser, da->id->prefix, da->id,
2487-
da->value, bindingsPtr);
2488-
if (result)
2489-
return result;
2490-
}
2491-
else {
2492-
(da->id->name)[-1] = 2;
2493-
nPrefixes++;
2494-
appAtts[attIndex++] = da->id->name;
2495-
appAtts[attIndex++] = da->value;
2496-
}
2456+
2457+
/* set-up for XML_GetSpecifiedAttributeCount and XML_GetIdAttributeIndex */
2458+
nSpecifiedAtts = attIndex;
2459+
if (elementType->idAtt && (elementType->idAtt->name)[-1]) {
2460+
for (i = 0; i < attIndex; i += 2)
2461+
if (appAtts[i] == elementType->idAtt->name) {
2462+
idAttIndex = i;
2463+
break;
2464+
}
2465+
}
2466+
else
2467+
idAttIndex = -1;
2468+
2469+
/* do attribute defaulting */
2470+
for (i = 0; i < nDefaultAtts; i++) {
2471+
const DEFAULT_ATTRIBUTE *da = elementType->defaultAtts + i;
2472+
if (!(da->id->name)[-1] && da->value) {
2473+
if (da->id->prefix) {
2474+
if (da->id->xmlns) {
2475+
enum XML_Error result = addBinding(parser, da->id->prefix, da->id,
2476+
da->value, bindingsPtr);
2477+
if (result)
2478+
return result;
24972479
}
24982480
else {
2499-
(da->id->name)[-1] = 1;
2481+
(da->id->name)[-1] = 2;
2482+
nPrefixes++;
25002483
appAtts[attIndex++] = da->id->name;
25012484
appAtts[attIndex++] = da->value;
25022485
}
25032486
}
2487+
else {
2488+
(da->id->name)[-1] = 1;
2489+
appAtts[attIndex++] = da->id->name;
2490+
appAtts[attIndex++] = da->value;
2491+
}
25042492
}
2505-
appAtts[attIndex] = 0;
25062493
}
2494+
appAtts[attIndex] = 0;
2495+
25072496
i = 0;
25082497
if (nPrefixes) {
25092498
/* expand prefixed attribute names */
@@ -2548,10 +2537,9 @@ storeAtts(XML_Parser parser, const ENCODING *enc,
25482537
/* clear the flags that say whether attributes were specified */
25492538
for (; i < attIndex; i += 2)
25502539
((XML_Char *)(appAtts[i]))[-1] = 0;
2551-
if (!tagNamePtr)
2552-
return XML_ERROR_NONE;
25532540
for (binding = *bindingsPtr; binding; binding = binding->nextTagBinding)
25542541
binding->attId->name[-1] = 0;
2542+
25552543
/* expand the element type name */
25562544
if (elementType->prefix) {
25572545
binding = elementType->prefix->binding;

0 commit comments

Comments
 (0)