cargilld 2005/04/04 08:11:38 Modified: c/src/xercesc/internal DGXMLScanner.cpp IGXMLScanner.cpp IGXMLScanner.hpp IGXMLScanner2.cpp ReaderMgr.hpp SGXMLScanner.cpp SGXMLScanner.hpp WFXMLScanner.cpp XMLReader.cpp XMLReader.hpp XSAXMLScanner.cpp Log: Fix a problem where illegal qualified names were not reported as errors. Also store the colon position when searching for a qualified name to avoid looking it up again. Revision Changes Path 1.62 +19 -30 xml-xerces/c/src/xercesc/internal/DGXMLScanner.cpp Index: DGXMLScanner.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/DGXMLScanner.cpp,v retrieving revision 1.61 retrieving revision 1.62 diff -u -r1.61 -r1.62 --- DGXMLScanner.cpp 12 Jan 2005 10:36:43 -0000 1.61 +++ DGXMLScanner.cpp 4 Apr 2005 15:11:37 -0000 1.62 @@ -786,8 +786,10 @@ // Get a name from the input, which should be the name of the root // element of the upcoming content. - fReaderMgr.getName(bbRootName.getBuffer()); - if (bbRootName.isEmpty()) + int colonPosition; + bool validName = fDoNamespaces ? fReaderMgr.getQName(bbRootName.getBuffer(), &colonPosition) : + fReaderMgr.getName(bbRootName.getBuffer()); + if (!validName) { emitError(XMLErrs::NoRootElemInDOCTYPE); fReaderMgr.skipPastChar(chCloseAngle); @@ -1094,7 +1096,11 @@ // Get the QName. In this case, we are not doing namespaces, so we just // use it as is and don't have to break it into parts. - if (!fReaderMgr.getName(fQNameBuf)) + + int colonPosition; + bool validName = fDoNamespaces ? fReaderMgr.getQName(fQNameBuf, &colonPosition) : + fReaderMgr.getName(fQNameBuf); + if (!validName) { emitError(XMLErrs::ExpectedElementName); fReaderMgr.skipToChar(chOpenAngle); @@ -1244,7 +1250,10 @@ { // Assume its going to be an attribute, so get a name from // the input. - if (!fReaderMgr.getName(fAttNameBuf)) + + validName = fDoNamespaces ? fReaderMgr.getQName(fAttNameBuf, &colonPosition) : + fReaderMgr.getName(fAttNameBuf); + if (!validName) { emitError(XMLErrs::ExpectedAttrName); fReaderMgr.skipPastChar(chCloseAngle); @@ -1472,30 +1481,6 @@ } } - if (fDoNamespaces) - { - // Make sure that the name is basically well formed for namespace - // enabled rules. It either has no colons, or it has one which - // is neither the first or last char. - const int colonFirst = XMLString::indexOf(fAttNameBuf.getRawBuffer(), chColon); - if (colonFirst != -1) - { - const int colonLast = XMLString::lastIndexOf(fAttNameBuf.getRawBuffer(), chColon); - - if (colonFirst != colonLast) - { - emitError(XMLErrs::TooManyColonsInName); - continue; - } - else if ((colonFirst == 0) - || (colonLast == (int)fAttNameBuf.getLen() - 1)) - { - emitError(XMLErrs::InvalidColonPos); - continue; - } - } - } - attCount++; // And jump back to the top of the loop @@ -3163,7 +3148,11 @@ // Expand it since its a normal entity ref XMLBufBid bbName(&fBufMgr); - if (!fReaderMgr.getName(bbName.getBuffer())) + + int colonPosition; + bool validName = fDoNamespaces ? fReaderMgr.getQName(bbName.getBuffer(), &colonPosition) : + fReaderMgr.getName(bbName.getBuffer()); + if (!validName) { emitError(XMLErrs::ExpectedEntityRefName); return EntityExp_Failed; 1.88 +61 -34 xml-xerces/c/src/xercesc/internal/IGXMLScanner.cpp Index: IGXMLScanner.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/IGXMLScanner.cpp,v retrieving revision 1.87 retrieving revision 1.88 diff -u -r1.87 -r1.88 --- IGXMLScanner.cpp 21 Feb 2005 18:19:45 -0000 1.87 +++ IGXMLScanner.cpp 4 Apr 2005 15:11:37 -0000 1.88 @@ -61,6 +61,8 @@ , fElemState(0) , fContent(1023, manager) , fRawAttrList(0) + , fRawAttrColonListSize(32) + , fRawAttrColonList(0) , fDTDValidator(0) , fSchemaValidator(0) , fDTDGrammar(0) @@ -111,6 +113,8 @@ , fElemState(0) , fContent(1023, manager) , fRawAttrList(0) + , fRawAttrColonListSize(32) + , fRawAttrColonList(0) , fDTDValidator(0) , fSchemaValidator(0) , fDTDGrammar(0) @@ -516,6 +520,10 @@ // And we need one for the raw attribute scan. This just stores key/ // value string pairs (prior to any processing.) fRawAttrList = new (fMemoryManager) RefVectorOf<KVStringPair>(32, true, fMemoryManager); + fRawAttrColonList = (int*) fMemoryManager->allocate + ( + fRawAttrColonListSize * sizeof(int) + ); // Create the Validator and init them fDTDValidator = new (fMemoryManager) DTDValidator(); @@ -550,6 +558,7 @@ { fMemoryManager->deallocate(fElemState); //delete [] fElemState; delete fRawAttrList; + fMemoryManager->deallocate(fRawAttrColonList); delete fDTDValidator; delete fSchemaValidator; delete fICHandler; @@ -625,7 +634,8 @@ { // Assume its going to be an attribute, so get a name from // the input. - if (!fReaderMgr.getName(fAttNameBuf)) + int colonPosition; + if (!fReaderMgr.getQName(fAttNameBuf, &colonPosition)) { emitError(XMLErrs::ExpectedAttrName); fReaderMgr.skipPastChar(chCloseAngle); @@ -710,27 +720,6 @@ } } - // Make sure that the name is basically well formed for namespace - // enabled rules. It either has no colons, or it has one which - // is neither the first or last char. - const int colonFirst = XMLString::indexOf(curAttNameBuf, chColon); - if (colonFirst != -1) - { - const int colonLast = XMLString::lastIndexOf(chColon, curAttNameBuf, fAttNameBuf.getLen()); - - if (colonFirst != colonLast) - { - emitError(XMLErrs::TooManyColonsInName); - continue; - } - else if ((colonFirst == 0) - || (colonLast == (int)fAttNameBuf.getLen() - 1)) - { - emitError(XMLErrs::InvalidColonPos); - continue; - } - } - // And now lets add it to the passed collection. If we have not // filled it up yet, then we use the next element. Else we add // a new one. @@ -745,9 +734,9 @@ , fAttValueBuf.getLen() , fMemoryManager ); - toFill.addElement(curPair); + toFill.addElement(curPair); } - else + else { curPair = toFill.elementAt(attCount); curPair->set @@ -756,8 +745,14 @@ fAttNameBuf.getLen(), fAttValueBuf.getRawBuffer(), fAttValueBuf.getLen() - ); + ); + } + + if (attCount >= fRawAttrColonListSize) { + resizeRawAttrColonList(); } + fRawAttrColonList[attCount] = colonPosition; + // And bump the count of attributes we've gotten attCount++; @@ -1244,8 +1239,10 @@ // Get a name from the input, which should be the name of the root // element of the upcoming content. - fReaderMgr.getName(bbRootName.getBuffer()); - if (bbRootName.isEmpty()) + int colonPosition; + bool validName = fDoNamespaces ? fReaderMgr.getQName(bbRootName.getBuffer(), &colonPosition) : + fReaderMgr.getName(bbRootName.getBuffer()); + if (!validName) { emitError(XMLErrs::NoRootElemInDOCTYPE); fReaderMgr.skipPastChar(chCloseAngle); @@ -2125,7 +2122,8 @@ // The current position is after the open bracket, so we need to read in // in the element name. - if (!fReaderMgr.getName(fQNameBuf)) + int prefixColonPos; + if (!fReaderMgr.getQName(fQNameBuf, &prefixColonPos)) { emitError(XMLErrs::ExpectedElementName); fReaderMgr.skipToChar(chOpenAngle); @@ -2252,10 +2250,9 @@ // Resolve the qualified name to a URI and name so that we can look up // the element decl for this element. We have now update the prefix to - // namespace map so we should get the correct element now. - int prefixColonPos = -1; + // namespace map so we should get the correct element now. const XMLCh* qnameRawBuf = fQNameBuf.getRawBuffer(); - unsigned int uriId = resolveQName + unsigned int uriId = resolveQNameWithColon ( qnameRawBuf , fPrefixBuf @@ -2967,15 +2964,25 @@ } + unsigned int IGXMLScanner::resolveQName(const XMLCh* const qName , XMLBuffer& prefixBuf , const short mode , int& prefixColonPos) { - // Lets split out the qName into a URI and name buffer first. The URI - // can be empty. prefixColonPos = XMLString::indexOf(qName, chColon); + return resolveQNameWithColon(qName, prefixBuf, mode, prefixColonPos); +} + +unsigned int +IGXMLScanner::resolveQNameWithColon(const XMLCh* const qName + , XMLBuffer& prefixBuf + , const short mode + , const int prefixColonPos) +{ + // Lets split out the qName into a URI and name buffer first. The URI + // can be empty. if (prefixColonPos == -1) { // Its all name with no prefix, so put the whole thing into the name @@ -3048,6 +3055,26 @@ fElemStateSize = newSize; } +void IGXMLScanner::resizeRawAttrColonList() { + + unsigned int newSize = fRawAttrColonListSize * 2; + int* newRawAttrColonList = (int*) fMemoryManager->allocate + ( + newSize * sizeof(int) + ); //new int[newSize]; + + // Copy the existing values + unsigned int index = 0; + for (; index < fRawAttrColonListSize; index++) + newRawAttrColonList[index] = fRawAttrColonList[index]; + + // Delete the old array and udpate our members + fMemoryManager->deallocate(fRawAttrColonList); //delete [] fRawAttrColonList; + fRawAttrColonList = newRawAttrColonList; + fRawAttrColonListSize = newSize; +} + + // --------------------------------------------------------------------------- // IGXMLScanner: Grammar preparsing // --------------------------------------------------------------------------- 1.26 +20 -0 xml-xerces/c/src/xercesc/internal/IGXMLScanner.hpp Index: IGXMLScanner.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/IGXMLScanner.hpp,v retrieving revision 1.25 retrieving revision 1.26 diff -u -r1.25 -r1.26 --- IGXMLScanner.hpp 14 Dec 2004 16:16:36 -0000 1.25 +++ IGXMLScanner.hpp 4 Apr 2005 15:11:37 -0000 1.26 @@ -16,6 +16,9 @@ /* * $Log$ + * Revision 1.26 2005/04/04 15:11:37 cargilld + * Fix a problem where illegal qualified names were not reported as errors. Also store the colon position when searching for a qualified name to avoid looking it up again. + * * Revision 1.25 2004/12/14 16:16:36 cargilld * Fix for xercesc-684: Add accessor to XMLScanner to get the current grammar type. * @@ -240,7 +243,13 @@ void updateNSMap ( const XMLCh* const attrName + , const XMLCh* const attrValue + ); + void updateNSMap + ( + const XMLCh* const attrName , const XMLCh* const attrValue + , const int colonPosition ); void scanRawAttrListforNameSpaces(int attCount); void parseSchemaLocation(const XMLCh* const schemaLocationStr); @@ -256,6 +265,15 @@ void resizeElemState(); void processSchemaLocation(XMLCh* const schemaLoc); + void resizeRawAttrColonList(); + + unsigned int resolveQNameWithColon + ( + const XMLCh* const qName + , XMLBuffer& prefixBufToFill + , const short mode + , const int prefixColonPos + ); // ----------------------------------------------------------------------- // Private scanning methods // ----------------------------------------------------------------------- @@ -347,6 +365,8 @@ unsigned int* fElemState; XMLBuffer fContent; RefVectorOf<KVStringPair>* fRawAttrList; + unsigned int fRawAttrColonListSize; + int* fRawAttrColonList; DTDValidator* fDTDValidator; SchemaValidator* fSchemaValidator; DTDGrammar* fDTDGrammar; 1.83 +16 -7 xml-xerces/c/src/xercesc/internal/IGXMLScanner2.cpp Index: IGXMLScanner2.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/IGXMLScanner2.cpp,v retrieving revision 1.82 retrieving revision 1.83 diff -u -r1.82 -r1.83 --- IGXMLScanner2.cpp 11 Mar 2005 17:06:28 -0000 1.82 +++ IGXMLScanner2.cpp 4 Apr 2005 15:11:37 -0000 1.83 @@ -143,7 +143,7 @@ // use a stack-based buffer when possible. XMLCh tempBuffer[100]; - const int colonInd = XMLString::indexOf(namePtr, chColon); + const int colonInd = fRawAttrColonList[index]; const XMLCh* prefPtr = XMLUni::fgZeroLenString; const XMLCh* suffPtr = XMLUni::fgZeroLenString; if (colonInd != -1) @@ -1488,6 +1488,13 @@ void IGXMLScanner::updateNSMap(const XMLCh* const attrName , const XMLCh* const attrValue) { + updateNSMap(attrName, attrValue, XMLString::indexOf(attrName, chColon)); +} + +void IGXMLScanner::updateNSMap(const XMLCh* const attrName + , const XMLCh* const attrValue + , const int colonOfs) +{ // We need a buffer to normalize the attribute value into XMLBufBid bbNormal(&fBufMgr); XMLBuffer& normalBuf = bbNormal.getBuffer(); @@ -1507,8 +1514,7 @@ // 2. if xxx is xml, then yyy must match XMLUni::fgXMLURIName, and vice versa // 3. yyy is not XMLUni::fgXMLNSURIName // 4. if xxx is not null, then yyy cannot be an empty string. - const XMLCh* prefPtr = XMLUni::fgZeroLenString; - const int colonOfs = XMLString::indexOf(attrName, chColon); + const XMLCh* prefPtr = XMLUni::fgZeroLenString; if (colonOfs != -1) { prefPtr = &attrName[colonOfs + 1]; @@ -1563,7 +1569,7 @@ { const XMLCh* valuePtr = curPair->getValue(); - updateNSMap(rawPtr, valuePtr); + updateNSMap(rawPtr, valuePtr, fRawAttrColonList[index]); // if the schema URI is seen in the the valuePtr, set the boolean seeXsi if (XMLString::equals(valuePtr, SchemaSymbols::fgURI_XSI)) { @@ -1585,7 +1591,7 @@ const KVStringPair* curPair = fRawAttrList->elementAt(index); const XMLCh* rawPtr = curPair->getKey(); const XMLCh* prefPtr = XMLUni::fgZeroLenString; - int colonInd = XMLString::indexOf(rawPtr, chColon); + int colonInd = fRawAttrColonList[index]; if (colonInd != -1) { @@ -2857,7 +2863,10 @@ // Expand it since its a normal entity ref XMLBufBid bbName(&fBufMgr); - if (!fReaderMgr.getName(bbName.getBuffer())) + int colonPosition; + bool validName = fDoNamespaces ? fReaderMgr.getQName(bbName.getBuffer(), &colonPosition) : + fReaderMgr.getName(bbName.getBuffer()); + if (!validName) { emitError(XMLErrs::ExpectedEntityRefName); return EntityExp_Failed; 1.17 +10 -0 xml-xerces/c/src/xercesc/internal/ReaderMgr.hpp Index: ReaderMgr.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/ReaderMgr.hpp,v retrieving revision 1.16 retrieving revision 1.17 diff -u -r1.16 -r1.17 --- ReaderMgr.hpp 9 Mar 2005 16:07:11 -0000 1.16 +++ ReaderMgr.hpp 4 Apr 2005 15:11:38 -0000 1.17 @@ -16,6 +16,9 @@ /* * $Log$ + * Revision 1.17 2005/04/04 15:11:38 cargilld + * Fix a problem where illegal qualified names were not reported as errors. Also store the colon position when searching for a qualified name to avoid looking it up again. + * * Revision 1.16 2005/03/09 16:07:11 amassari * Protected getSrcOffset to avoid crashing when parsing has finished; updated documentation * @@ -183,6 +186,7 @@ // ----------------------------------------------------------------------- bool atEOF() const; bool getName(XMLBuffer& toFill); + bool getQName(XMLBuffer& toFill, int* colonPosition); bool getNameToken(XMLBuffer& toFill); XMLCh getNextChar(); bool getNextCharIfNot(const XMLCh chNotToGet, XMLCh& chGotten); @@ -392,6 +396,12 @@ return fCurReader->getName(toFill, false); } +inline bool ReaderMgr::getQName(XMLBuffer& toFill, int *colonPosition) +{ + toFill.reset(); + return fCurReader->getQName(toFill, colonPosition); +} + inline bool ReaderMgr::getNameToken(XMLBuffer& toFill) { toFill.reset(); 1.110 +63 -35 xml-xerces/c/src/xercesc/internal/SGXMLScanner.cpp Index: SGXMLScanner.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/SGXMLScanner.cpp,v retrieving revision 1.109 retrieving revision 1.110 diff -u -r1.109 -r1.110 --- SGXMLScanner.cpp 21 Feb 2005 18:19:45 -0000 1.109 +++ SGXMLScanner.cpp 4 Apr 2005 15:11:38 -0000 1.110 @@ -66,6 +66,8 @@ , fContent(1023, manager) , fEntityTable(0) , fRawAttrList(0) + , fRawAttrColonListSize(32) + , fRawAttrColonList(0) , fSchemaGrammar(0) , fSchemaValidator(0) , fICHandler(0) @@ -119,6 +121,8 @@ , fContent(1023, manager) , fEntityTable(0) , fRawAttrList(0) + , fRawAttrColonListSize(32) + , fRawAttrColonList(0) , fSchemaGrammar(0) , fSchemaValidator(0) , fICHandler(0) @@ -556,7 +560,8 @@ { // Assume its going to be an attribute, so get a name from // the input. - if (!fReaderMgr.getName(fAttNameBuf)) + int colonPosition; + if (!fReaderMgr.getQName(fAttNameBuf, &colonPosition)) { emitError(XMLErrs::ExpectedAttrName); fReaderMgr.skipPastChar(chCloseAngle); @@ -641,27 +646,6 @@ } } - // Make sure that the name is basically well formed for namespace - // enabled rules. It either has no colons, or it has one which - // is neither the first or last char. - const int colonFirst = XMLString::indexOf(curAttNameBuf, chColon); - if (colonFirst != -1) - { - const int colonLast = XMLString::lastIndexOf(chColon, curAttNameBuf, fAttNameBuf.getLen()); - - if (colonFirst != colonLast) - { - emitError(XMLErrs::TooManyColonsInName); - continue; - } - else if ((colonFirst == 0) - || (colonLast == (int)fAttNameBuf.getLen() - 1)) - { - emitError(XMLErrs::InvalidColonPos); - continue; - } - } - // And now lets add it to the passed collection. If we have not // filled it up yet, then we use the next element. Else we add // a new one. @@ -689,6 +673,10 @@ , fAttValueBuf.getLen() ); } + if (attCount >= fRawAttrColonListSize) { + resizeRawAttrColonList(); + } + fRawAttrColonList[attCount] = colonPosition; // And bump the count of attributes we've gotten attCount++; @@ -1091,7 +1079,8 @@ // The current position is after the open bracket, so we need to read in // in the element name. - if (!fReaderMgr.getName(fQNameBuf)) + int prefixColonPos; + if (!fReaderMgr.getQName(fQNameBuf, &prefixColonPos)) { emitError(XMLErrs::ExpectedElementName); fReaderMgr.skipToChar(chOpenAngle); @@ -1179,9 +1168,8 @@ // Resolve the qualified name to a URI and name so that we can look up // the element decl for this element. We have now update the prefix to - // namespace map so we should get the correct element now. - int prefixColonPos = -1; - unsigned int uriId = resolveQName + // namespace map so we should get the correct element now. + unsigned int uriId = resolveQNameWithColon ( qnameRawBuf , fPrefixBuf @@ -1818,9 +1806,18 @@ , const short mode , int& prefixColonPos) { - // Lets split out the qName into a URI and name buffer first. The URI - // can be empty. prefixColonPos = XMLString::indexOf(qName, chColon); + return resolveQNameWithColon(qName, prefixBuf, mode, prefixColonPos); +} + +unsigned int +SGXMLScanner::resolveQNameWithColon(const XMLCh* const qName + , XMLBuffer& prefixBuf + , const short mode + , const int prefixColonPos) +{ + // Lets split out the qName into a URI and name buffer first. The URI + // can be empty. if (prefixColonPos == -1) { // Its all name with no prefix, so put the whole thing into the name @@ -1992,6 +1989,10 @@ // And we need one for the raw attribute scan. This just stores key/ // value string pairs (prior to any processing.) fRawAttrList = new (fMemoryManager) RefVectorOf<KVStringPair>(32, true, fMemoryManager); + fRawAttrColonList = (int*) fMemoryManager->allocate + ( + fRawAttrColonListSize * sizeof(int) + ); // Create the Validator and init them fSchemaValidator = new (fMemoryManager) SchemaValidator(0, fMemoryManager); @@ -2026,6 +2027,7 @@ delete fSchemaGrammar; delete fEntityTable; delete fRawAttrList; + fMemoryManager->deallocate(fRawAttrColonList); delete fSchemaValidator; delete fICHandler; delete fElemNonDeclPool; @@ -2061,6 +2063,25 @@ fElemStateSize = newSize; } +void SGXMLScanner::resizeRawAttrColonList() { + + unsigned int newSize = fRawAttrColonListSize * 2; + int* newRawAttrColonList = (int*) fMemoryManager->allocate + ( + newSize * sizeof(int) + ); //new int[newSize]; + + // Copy the existing values + unsigned int index = 0; + for (; index < fRawAttrColonListSize; index++) + newRawAttrColonList[index] = fRawAttrColonList[index]; + + // Delete the old array and udpate our members + fMemoryManager->deallocate(fRawAttrColonList); //delete [] fRawAttrColonList; + fRawAttrColonList = newRawAttrColonList; + fRawAttrColonListSize = newSize; +} + // This method is called from scanStartTag() to build up the list of // XMLAttr objects that will be passed out in the start tag callout. We // get the key/value pairs from the raw scan of explicitly provided attrs, @@ -2128,7 +2149,7 @@ // use a stack-based buffer when possible. XMLCh tempBuffer[100]; - const int colonInd = XMLString::indexOf(namePtr, chColon); + const int colonInd = fRawAttrColonList[index]; const XMLCh* prefPtr = XMLUni::fgZeroLenString; const XMLCh* suffPtr = XMLUni::fgZeroLenString; if (colonInd != -1) @@ -3320,6 +3341,13 @@ void SGXMLScanner::updateNSMap(const XMLCh* const attrName , const XMLCh* const attrValue) { + updateNSMap(attrName, attrValue, XMLString::indexOf(attrName, chColon)); +} + +void SGXMLScanner::updateNSMap(const XMLCh* const attrName + , const XMLCh* const attrValue + , const int colonOfs) +{ // We need a buffer to normalize the attribute value into XMLBufBid bbNormal(&fBufMgr); XMLBuffer& normalBuf = bbNormal.getBuffer(); @@ -3339,8 +3367,7 @@ // 2. if xxx is xml, then yyy must match XMLUni::fgXMLURIName, and vice versa // 3. yyy is not XMLUni::fgXMLNSURIName // 4. if xxx is not null, then yyy cannot be an empty string. - const XMLCh* prefPtr = XMLUni::fgZeroLenString; - const int colonOfs = XMLString::indexOf(attrName, chColon); + const XMLCh* prefPtr = XMLUni::fgZeroLenString; if (colonOfs != -1) { prefPtr = &attrName[colonOfs + 1]; @@ -3381,7 +3408,7 @@ // schema attributes. // When we find one, send it off to be used to update the element stack's // namespace mappings. - int index = 0; + int index; for (index = 0; index < attCount; index++) { // each attribute has the prefix:suffix="value" @@ -3395,7 +3422,7 @@ { const XMLCh* valuePtr = curPair->getValue(); - updateNSMap(rawPtr, valuePtr); + updateNSMap(rawPtr, valuePtr, fRawAttrColonList[index]); // if the schema URI is seen in the the valuePtr, set the boolean seeXsi if (XMLString::equals(valuePtr, SchemaSymbols::fgURI_XSI)) { @@ -4411,7 +4438,8 @@ // Expand it since its a normal entity ref XMLBufBid bbName(&fBufMgr); - if (!fReaderMgr.getName(bbName.getBuffer())) + int colonPosition; + if (!fReaderMgr.getQName(bbName.getBuffer(), &colonPosition)) { emitError(XMLErrs::ExpectedEntityRefName); return EntityExp_Failed; 1.24 +19 -1 xml-xerces/c/src/xercesc/internal/SGXMLScanner.hpp Index: SGXMLScanner.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/SGXMLScanner.hpp,v retrieving revision 1.23 retrieving revision 1.24 diff -u -r1.23 -r1.24 --- SGXMLScanner.hpp 14 Dec 2004 16:16:36 -0000 1.23 +++ SGXMLScanner.hpp 4 Apr 2005 15:11:38 -0000 1.24 @@ -16,6 +16,9 @@ /* * $Log$ + * Revision 1.24 2005/04/04 15:11:38 cargilld + * Fix a problem where illegal qualified names were not reported as errors. Also store the colon position when searching for a qualified name to avoid looking it up again. + * * Revision 1.23 2004/12/14 16:16:36 cargilld * Fix for xercesc-684: Add accessor to XMLScanner to get the current grammar type. * @@ -209,7 +212,20 @@ ); void resizeElemState(); - + void updateNSMap + ( + const XMLCh* const attrName + , const XMLCh* const attrValue + , const int colonPosition + ); + void resizeRawAttrColonList(); + unsigned int resolveQNameWithColon + ( + const XMLCh* const qName + , XMLBuffer& prefixBufToFill + , const short mode + , const int prefixColonPos + ); // ----------------------------------------------------------------------- // Data members // @@ -252,6 +268,8 @@ XMLBuffer fContent; ValueHashTableOf<XMLCh>* fEntityTable; RefVectorOf<KVStringPair>* fRawAttrList; + unsigned int fRawAttrColonListSize; + int* fRawAttrColonList; SchemaGrammar* fSchemaGrammar; SchemaValidator* fSchemaValidator; IdentityConstraintHandler* fICHandler; 1.29 +5 -24 xml-xerces/c/src/xercesc/internal/WFXMLScanner.cpp Index: WFXMLScanner.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/WFXMLScanner.cpp,v retrieving revision 1.28 retrieving revision 1.29 diff -u -r1.28 -r1.29 --- WFXMLScanner.cpp 12 Jan 2005 10:37:32 -0000 1.28 +++ WFXMLScanner.cpp 4 Apr 2005 15:11:38 -0000 1.29 @@ -1097,7 +1097,8 @@ // The current position is after the open bracket, so we need to read in // in the element name. - if (!fReaderMgr.getName(fQNameBuf)) + int colonPosition; + if (!fReaderMgr.getQName(fQNameBuf, &colonPosition)) { emitError(XMLErrs::ExpectedElementName); fReaderMgr.skipToChar(chOpenAngle); @@ -1182,7 +1183,8 @@ { // Assume its going to be an attribute, so get a name from // the input. - if (!fReaderMgr.getName(fAttNameBuf)) + int colonPosition; + if (!fReaderMgr.getQName(fAttNameBuf, &colonPosition)) { emitError(XMLErrs::ExpectedAttrName); fReaderMgr.skipPastChar(chCloseAngle); @@ -1322,27 +1324,6 @@ fAttrNameHashList->setElementAt(attNameHash, attCount); } - // Make sure that the name is basically well formed for namespace - // enabled rules. It either has no colons, or it has one which - // is neither the first or last char. - const int colonFirst = XMLString::indexOf(attNameRawBuf, chColon); - if (colonFirst != -1) - { - const int colonLast = XMLString::lastIndexOf(attNameRawBuf, chColon); - - if (colonFirst != colonLast) - { - emitError(XMLErrs::TooManyColonsInName); - continue; - } - else if ((colonFirst == 0) - || (colonLast == (int)fAttNameBuf.getLen() - 1)) - { - emitError(XMLErrs::InvalidColonPos); - continue; - } - } - // Map prefix to namespace const XMLCh* attPrefix = curAtt->getPrefix(); const XMLCh* attLocalName = curAtt->getName(); 1.30 +164 -6 xml-xerces/c/src/xercesc/internal/XMLReader.cpp Index: XMLReader.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/XMLReader.cpp,v retrieving revision 1.29 retrieving revision 1.30 diff -u -r1.29 -r1.30 --- XMLReader.cpp 22 Mar 2005 20:43:27 -0000 1.29 +++ XMLReader.cpp 4 Apr 2005 15:11:38 -0000 1.30 @@ -408,6 +408,7 @@ } if( fCharIndex < fCharsAvail ) { + return (fSrcOfsBase + fCharOfsBuf[fCharIndex]); } @@ -591,7 +592,7 @@ return false; } - unsigned int fCharIndex_start = fCharIndex; + unsigned int charIndex_start = fCharIndex; // Lets check the first char for being a first name char. If not, then // what's the point in living mannnn? Just give up now. We only do this @@ -658,10 +659,10 @@ } // we have to copy the accepted character(s), and update column - if (fCharIndex != fCharIndex_start) + if (fCharIndex != charIndex_start) { - fCurCol += fCharIndex - fCharIndex_start; - toFill.append(&fCharBuf[fCharIndex_start], fCharIndex - fCharIndex_start); + fCurCol += fCharIndex - charIndex_start; + toFill.append(&fCharBuf[charIndex_start], fCharIndex - charIndex_start); } // something is wrong if there is still something in the buffer @@ -670,12 +671,169 @@ !refreshCharBuffer()) break; - fCharIndex_start = fCharIndex; + charIndex_start = fCharIndex; } return !toFill.isEmpty(); } +bool XMLReader::getQName(XMLBuffer& toFill, int* colonPosition) +{ + // Ok, first lets see if we have chars in the buffer. If not, then lets + // reload. + if (fCharIndex == fCharsAvail) + { + if (!refreshCharBuffer()) + return false; + } + + unsigned int charIndex_start = fCharIndex; + *colonPosition = -1; + bool checkNextCharacterForFirstNCName = false; + + // Lets check the first char for being a first name char. If not, then + // what's the point in living mannnn? Just give up now. We only do this + // if its a name and not a name token that they want. + if (fXMLVersion == XMLV1_1 && ((fCharBuf[fCharIndex] >= 0xD800) && (fCharBuf[fCharIndex] <= 0xDB7F))) { + // make sure one more char is in the buffer, the transcoder + // should put only a complete surrogate pair into the buffer + assert(fCharIndex+1 < fCharsAvail); + if ((fCharBuf[fCharIndex+1] < 0xDC00) || (fCharBuf[fCharIndex+1] > 0xDFFF)) + return false; + + // Looks ok, so lets eat it + fCharIndex += 2; + } + else { + if (!isFirstNameChar(fCharBuf[fCharIndex])) + return false; + if (fCharBuf[fCharIndex] == chColon) + return false; + // Looks ok, so lets eat it + fCharIndex ++; + } + + // And now we loop until we run out of data in this reader or we hit + // a non-name char. + while (true) + { + if (checkNextCharacterForFirstNCName) { + checkNextCharacterForFirstNCName = false; + if (fXMLVersion == XMLV1_1) { + if ( !((fCharBuf[fCharIndex] >= 0xD800) && (fCharBuf[fCharIndex] <= 0xDB7F)) ) + { + if (!isFirstNameChar(fCharBuf[fCharIndex])) + return false; + if (fCharBuf[fCharIndex] == chColon) + return false; + fCharIndex++; + } + } + else { + if (!isFirstNameChar(fCharBuf[fCharIndex])) + return false; + if (fCharBuf[fCharIndex] == chColon) + return false; + fCharIndex++; + } + + } + + if (fXMLVersion == XMLV1_1) + { + while (fCharIndex < fCharsAvail) + { + // Check the current char and take it if its a name char. Else + // break out. + if ( (fCharBuf[fCharIndex] >= 0xD800) && (fCharBuf[fCharIndex] <= 0xDB7F) ) + { + // make sure one more char is in the buffer, the transcoder + // should put only a complete surrogate pair into the buffer + assert(fCharIndex+1 < fCharsAvail); + if ( (fCharBuf[fCharIndex+1] < 0xDC00) || + (fCharBuf[fCharIndex+1] > 0xDFFF) ) + break; + fCharIndex += 2; + + } + else + { + if (!isNameChar(fCharBuf[fCharIndex])) + break; + if (fCharBuf[fCharIndex] == chColon) { + if (*colonPosition != -1) { + return false; + } + // update the buffer to get the colon Offset position + fCurCol += fCharIndex - charIndex_start; + toFill.append(&fCharBuf[charIndex_start], fCharIndex - charIndex_start); + charIndex_start = fCharIndex; + *colonPosition = toFill.getLen(); + if (fCharIndex + 1 < fCharsAvail) { + fCharIndex++; + if (!isFirstNameChar(fCharBuf[fCharIndex])) + return false; + if (fCharBuf[fCharIndex] == chColon) + return false; + } + else { + checkNextCharacterForFirstNCName = true; + } + } + fCharIndex++; + } + } + } + else // XMLV1_0 + { + while (fCharIndex < fCharsAvail) + { + if (!isNameChar(fCharBuf[fCharIndex])) + break; + if (fCharBuf[fCharIndex] == chColon) { + if (*colonPosition != -1) { + return false; + } + // update the buffer to get the colon Offset position + fCurCol += fCharIndex - charIndex_start; + toFill.append(&fCharBuf[charIndex_start], fCharIndex - charIndex_start); + charIndex_start = fCharIndex; + *colonPosition = toFill.getLen(); + if (fCharIndex + 1 < fCharsAvail) { + fCharIndex++; + if (!isFirstNameChar(fCharBuf[fCharIndex])) + return false; + if (fCharBuf[fCharIndex] == chColon) + return false; + } + else { + checkNextCharacterForFirstNCName = true; + } + } + fCharIndex++; + } + } + + // we have to copy the accepted character(s), and update column + if (fCharIndex != charIndex_start) + { + fCurCol += fCharIndex - charIndex_start; + toFill.append(&fCharBuf[charIndex_start], fCharIndex - charIndex_start); + } + + // something is wrong if there is still something in the buffer + // or if we don't get no more, then break out. + if ((fCharIndex < fCharsAvail) || + !refreshCharBuffer()) + break; + + charIndex_start = fCharIndex; + } + + if (checkNextCharacterForFirstNCName) + return false; + return !toFill.isEmpty(); +} bool XMLReader::getSpaces(XMLBuffer& toFill) { 1.22 +5 -1 xml-xerces/c/src/xercesc/internal/XMLReader.hpp Index: XMLReader.hpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/XMLReader.hpp,v retrieving revision 1.21 retrieving revision 1.22 diff -u -r1.21 -r1.22 --- XMLReader.hpp 22 Mar 2005 20:43:27 -0000 1.21 +++ XMLReader.hpp 4 Apr 2005 15:11:38 -0000 1.22 @@ -16,6 +16,9 @@ /* * $Log$ + * Revision 1.22 2005/04/04 15:11:38 cargilld + * Fix a problem where illegal qualified names were not reported as errors. Also store the colon position when searching for a qualified name to avoid looking it up again. + * * Revision 1.21 2005/03/22 20:43:27 cargilld * Check in Christian's patches for Xercesc-1369 and 1370. * @@ -233,7 +236,7 @@ bool isXMLLetter(const XMLCh toCheck) const; bool isFirstNameChar(const XMLCh toCheck) const; - bool isNameChar(const XMLCh toCheck) const; + bool isNameChar(const XMLCh toCheck) const; bool isPlainContentChar(const XMLCh toCheck) const; bool isSpecialStartTagChar(const XMLCh toCheck) const; bool isXMLChar(const XMLCh toCheck) const; @@ -302,6 +305,7 @@ // Scanning methods // ----------------------------------------------------------------------- bool getName(XMLBuffer& toFill, const bool token); + bool getQName(XMLBuffer& toFill, int* colonPosition); bool getNextChar(XMLCh& chGotten); bool getNextCharIfNot(const XMLCh chNotToGet, XMLCh& chGotten); void movePlainContentChars(XMLBuffer &dest); 1.7 +6 -6 xml-xerces/c/src/xercesc/internal/XSAXMLScanner.cpp Index: XSAXMLScanner.cpp =================================================================== RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/XSAXMLScanner.cpp,v retrieving revision 1.6 retrieving revision 1.7 diff -u -r1.6 -r1.7 --- XSAXMLScanner.cpp 19 Feb 2005 23:44:17 -0000 1.6 +++ XSAXMLScanner.cpp 4 Apr 2005 15:11:38 -0000 1.7 @@ -192,7 +192,8 @@ // The current position is after the open bracket, so we need to read in // in the element name. - if (!fReaderMgr.getName(fQNameBuf)) + int prefixColonPos; + if (!fReaderMgr.getQName(fQNameBuf, &prefixColonPos)) { emitError(XMLErrs::ExpectedElementName); fReaderMgr.skipToChar(chOpenAngle); @@ -263,9 +264,8 @@ // Resolve the qualified name to a URI and name so that we can look up // the element decl for this element. We have now update the prefix to - // namespace map so we should get the correct element now. - int prefixColonPos = -1; - unsigned int uriId = resolveQName + // namespace map so we should get the correct element now. + unsigned int uriId = resolveQNameWithColon ( qnameRawBuf, fPrefixBuf, ElemStack::Mode_Element, prefixColonPos ); @@ -612,7 +612,7 @@ { const XMLCh* valuePtr = curPair->getValue(); - updateNSMap(rawPtr, valuePtr); + updateNSMap(rawPtr, valuePtr, fRawAttrColonList[index]); // if the schema URI is seen in the the valuePtr, set the boolean seeXsi if (XMLString::equals(valuePtr, SchemaSymbols::fgURI_XSI)) {
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]