| 7611 | } |
| 7612 | |
| 7613 | static xmlEntityPtr |
| 7614 | xmlLookupGeneralEntity(xmlParserCtxtPtr ctxt, const xmlChar *name, int inAttr) { |
| 7615 | xmlEntityPtr ent; |
| 7616 | |
| 7617 | /* |
| 7618 | * Predefined entities override any extra definition |
| 7619 | */ |
| 7620 | if ((ctxt->options & XML_PARSE_OLDSAX) == 0) { |
| 7621 | ent = xmlGetPredefinedEntity(name); |
| 7622 | if (ent != NULL) |
| 7623 | return(ent); |
| 7624 | } |
| 7625 | |
| 7626 | /* |
| 7627 | * Ask first SAX for entity resolution, otherwise try the |
| 7628 | * entities which may have stored in the parser context. |
| 7629 | */ |
| 7630 | if (ctxt->sax != NULL) { |
| 7631 | if (ctxt->sax->getEntity != NULL) |
| 7632 | ent = ctxt->sax->getEntity(ctxt->userData, name); |
| 7633 | if ((ctxt->wellFormed == 1 ) && (ent == NULL) && |
| 7634 | (ctxt->options & XML_PARSE_OLDSAX)) |
| 7635 | ent = xmlGetPredefinedEntity(name); |
| 7636 | if ((ctxt->wellFormed == 1 ) && (ent == NULL) && |
| 7637 | (ctxt->userData==ctxt)) { |
| 7638 | ent = xmlSAX2GetEntity(ctxt, name); |
| 7639 | } |
| 7640 | } |
| 7641 | |
| 7642 | if (ent == NULL) { |
| 7643 | xmlHandleUndeclaredEntity(ctxt, name); |
| 7644 | } |
| 7645 | |
| 7646 | /* |
| 7647 | * [ WFC: Parsed Entity ] |
| 7648 | * An entity reference must not contain the name of an |
| 7649 | * unparsed entity |
| 7650 | */ |
| 7651 | else if (ent->etype == XML_EXTERNAL_GENERAL_UNPARSED_ENTITY) { |
| 7652 | xmlFatalErrMsgStr(ctxt, XML_ERR_UNPARSED_ENTITY, |
| 7653 | "Entity reference to unparsed entity %s\n", name); |
| 7654 | ent = NULL; |
| 7655 | } |
| 7656 | |
| 7657 | /* |
| 7658 | * [ WFC: No External Entity References ] |
| 7659 | * Attribute values cannot contain direct or indirect |
| 7660 | * entity references to external entities. |
| 7661 | */ |
| 7662 | else if (ent->etype == XML_EXTERNAL_GENERAL_PARSED_ENTITY) { |
| 7663 | if (inAttr) { |
| 7664 | xmlFatalErrMsgStr(ctxt, XML_ERR_ENTITY_IS_EXTERNAL, |
| 7665 | "Attribute references external entity '%s'\n", name); |
| 7666 | ent = NULL; |
| 7667 | } |
| 7668 | } |
| 7669 | |
| 7670 | return(ent); |
no test coverage detected