tng         2002/11/26 12:20:43

  Modified:    c/src/xercesc/internal XMLScanner.cpp XMLScanner2.cpp
  Log:
  Namespace Check:
  1. xmlns:a="" where namespace URI is null is not valid
  2. xmlns:doc where xmlns is used as element prefix is not valid
  3. xmlns:xmlns where xmlns is used as prefix is not valid
  4. xmlns:xml="a" where xml is used as prefix but URI does not match the xml uri 
(http://www.w3.org/XML/1999/namespace) is not valid
  
  Revision  Changes    Path
  1.26      +7 -2      xml-xerces/c/src/xercesc/internal/XMLScanner.cpp
  
  Index: XMLScanner.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/XMLScanner.cpp,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- XMLScanner.cpp    15 Nov 2002 21:57:43 -0000      1.25
  +++ XMLScanner.cpp    26 Nov 2002 20:20:42 -0000      1.26
  @@ -4153,8 +4153,13 @@
           //  to map to by the NS spec. xmlns gets mapped to a special place holder
           //  URI that we define (so that it maps to something checkable.)
           //
  -        if (XMLString::equals(prefixBuf.getRawBuffer(), XMLUni::fgXMLNSString))
  +        if (XMLString::equals(prefixBuf.getRawBuffer(), XMLUni::fgXMLNSString)) {
               uriId = fXMLNSNamespaceId;
  +
  +            // if this is an element, it is an error to have xmlns as prefix
  +            if (mode == ElemStack::Mode_Element)
  +                emitError(XMLErrs::NoXMLNSAsElementPrefix, qName);
  +        }
           else if (XMLString::equals(prefixBuf.getRawBuffer(), XMLUni::fgXMLString))
               uriId = fXMLNamespaceId;
           else
  
  
  
  1.20      +40 -10    xml-xerces/c/src/xercesc/internal/XMLScanner2.cpp
  
  Index: XMLScanner2.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xerces/c/src/xercesc/internal/XMLScanner2.cpp,v
  retrieving revision 1.19
  retrieving revision 1.20
  diff -u -r1.19 -r1.20
  --- XMLScanner2.cpp   7 Nov 2002 21:59:13 -0000       1.19
  +++ XMLScanner2.cpp   26 Nov 2002 20:20:43 -0000      1.20
  @@ -1267,11 +1267,17 @@
   
   //
   //  This method is called with a key/value string pair that represents an
  -//  xmlns="xxx" or xmlns:xxx="yyy" attribute. This method will update the
  +//  xmlns="yyy" or xmlns:xxx="yyy" attribute. This method will update the
   //  current top of the element stack based on this data. We know that when
   //  we get here, that it is one of these forms, so we don't bother confirming
   //  it.
   //
  +//  But we have to ensure
  +//      1. xxx is not xmlns
  +//      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.
  +//
   void XMLScanner::updateNSMap(const  XMLCh* const    attrName
                               , const XMLCh* const    attrValue)
   {
  @@ -1279,22 +1285,46 @@
       XMLBufBid bbNormal(&fBufMgr);
       XMLBuffer& normalBuf = bbNormal.getBuffer();
   
  +    //
  +    //  Normalize the value into the passed buffer. In this case, we don't
  +    //  care about the return value. An error was issued for the error, which
  +    //  is all we care about here.
  +    //
  +    normalizeAttRawValue(attrName, attrValue, normalBuf);
  +    XMLCh* namespaceURI = normalBuf.getRawBuffer();
  +
       //  We either have the default prefix (""), or we point it into the attr
       //  name parameter. Note that the xmlns is not the prefix we care about
       //  here. To us, the 'prefix' is really the local part of the attrName
       //  parameter.
       //
  +    //  Check 1. xxx is not xmlns
  +    //        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 unsigned int colonOfs = XMLString::indexOf(attrName, chColon);
  -    if (colonOfs != -1)
  +    if (colonOfs != -1) {
           prefPtr = &attrName[colonOfs + 1];
   
  -    //
  -    //  Normalize the value into the passed buffer. In this case, we don't
  -    //  care about the return value. An error was issued for the error, which
  -    //  is all we care about here.
  -    //
  -    normalizeAttRawValue(attrName, attrValue, normalBuf);
  +        if (XMLString::equals(prefPtr, XMLUni::fgXMLNSString))
  +            emitError(XMLErrs::NoUseOfxmlnsAsPrefix);
  +        else if (XMLString::equals(prefPtr, XMLUni::fgXMLString)) {
  +            if (!XMLString::equals(namespaceURI, XMLUni::fgXMLURIName))
  +                emitError(XMLErrs::PrefixXMLNotMatchXMLURI);
  +        }
  +
  +        if (!namespaceURI || !*namespaceURI)
  +            emitError(XMLErrs::NoEmptyStrNamespace, attrName);
  +    }
  +
  +    if (XMLString::equals(namespaceURI, XMLUni::fgXMLNSURIName))
  +        emitError(XMLErrs::NoUseOfxmlnsURI);
  +    else if (XMLString::equals(namespaceURI, XMLUni::fgXMLURIName)) {
  +        if (!XMLString::equals(prefPtr, XMLUni::fgXMLString))
  +            emitError(XMLErrs::XMLURINotMatchXMLPrefix);
  +    }
   
       //
       //  Ok, we have to get the unique id for the attribute value, which is the
  @@ -1305,7 +1335,7 @@
       fElemStack.addPrefix
       (
           prefPtr
  -        , fURIStringPool->addOrFind(normalBuf.getRawBuffer())
  +        , fURIStringPool->addOrFind(namespaceURI)
       );
   }
   
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to