dbertoni    01/11/26 15:16:02

  Modified:    c/src/XPath XPathProcessorImpl.cpp XPathProcessorImpl.hpp
  Log:
  Better error detection.  Fixes bugs 5049 and 5093.
  
  Revision  Changes    Path
  1.46      +87 -19    xml-xalan/c/src/XPath/XPathProcessorImpl.cpp
  
  Index: XPathProcessorImpl.cpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathProcessorImpl.cpp,v
  retrieving revision 1.45
  retrieving revision 1.46
  diff -u -r1.45 -r1.46
  --- XPathProcessorImpl.cpp    2001/11/16 19:34:22     1.45
  +++ XPathProcessorImpl.cpp    2001/11/26 23:16:02     1.46
  @@ -2,7 +2,7 @@
    * The Apache Software License, Version 1.1
    *
    *
  - * Copyright (c) 1999 The Apache Software Foundation.  All rights 
  + * Copyright (c) 1999-2001 The Apache Software Foundation.  All rights 
    * reserved.
    *
    * Redistribution and use in source and binary forms, with or without
  @@ -715,7 +715,7 @@
                        XalanDOMChar    c,
                        int                     n) const
   {
  -     const XalanDOMString    tok =
  +     const XalanDOMString&   tok =
                getTokenRelative(n - 1);
   
        if (length(tok) == 1 &&
  @@ -738,7 +738,7 @@
   {
        assert(s != 0);
   
  -     const XalanDOMString    tok =
  +     const XalanDOMString&   tok =
                getTokenRelative(n - 1);
   
        return equals(tok, s);
  @@ -751,7 +751,7 @@
                        const XalanDOMString&   s,
                        int                                             n) const
   {
  -     const XalanDOMString    tok =
  +     const XalanDOMString&   tok =
                getTokenRelative(n - 1);
   
        return equals(tok, s);
  @@ -764,7 +764,7 @@
                        char    c,
                        int     n) const
   {
  -     const XalanDOMString    tok =
  +     const XalanDOMString&   tok =
                getTokenRelative(-(n + 1));
   
        if (length(tok) == 1 &&
  @@ -783,7 +783,7 @@
   bool
   XPathProcessorImpl::lookbehindHasToken(int   n) const
   {
  -     const XalanDOMString    tok =
  +     const XalanDOMString&   tok =
                getTokenRelative(-(n + 1));
   
        const XalanDOMChar              c0 = length(tok) == 0 ? 
XalanUnicode::charVerticalLine : charAt(tok, 0);
  @@ -844,7 +844,7 @@
   
   
   
  -XalanDOMString
  +const XalanDOMString&
   XPathProcessorImpl::getTokenRelative(int     theOffset) const
   {
        assert(m_expression != 0);
  @@ -852,7 +852,7 @@
        const XObject* const    theToken =
                m_expression->getRelativeToken(theOffset);
   
  -     return theToken == 0 ? XalanDOMString() : theToken->str();
  +     return theToken == 0 ? s_emptyString : theToken->str();
   }
   
   
  @@ -1905,14 +1905,19 @@
        }
        else if(tokenIs(XalanUnicode::charSolidus) == true)
        {
  -             axisType = XPathExpression::eFROM_DESCENDANTS_OR_SELF;
  +             // Check the current token in the expression.  It's
  +             // actually the next token in this context.
  +             //
  +             const XalanDOMString&   theNextToken = getTokenRelative(0);
   
  -             // Have to fix up for patterns such as '//@foo' or 
'//attribute::foo',
  -             // which translate to 
'descendant-or-self::node()/attribute::foo'.
  -             // notice I leave the '/' on the queue, so the next will be 
processed 
  -             // by a regular step pattern.
  -             // if(lookahead(XalanUnicode::charCommercialAt, 1) == true || 
lookahead("::", 2) == true)
  +             if (isAxis(theNextToken) == false && isNodeTest(theNextToken) 
== false)
                {
  +                     nextToken();
  +
  +                     error("Expected axis or node test!");
  +             }
  +             else
  +             {
                        // Tell how long the step is without the predicate
                        const XPathExpression::OpCodeMapValueVectorType         
theArgs(1, 4);
   
  @@ -1926,10 +1931,6 @@
   
                        return; // make a quick exit...
                }
  -             //else
  -             //{
  -             //      nextToken();
  -             //}
        }
        else
        {
  @@ -1952,7 +1953,7 @@
        assert(m_xpath != 0);
        assert(m_expression != 0);
   
  -     AxisNamesMapType::const_iterator        i =
  +     const AxisNamesMapType::const_iterator  i =
                s_axisNames.find(m_token);
   
        if (i == s_axisNames.end())
  @@ -2034,6 +2035,10 @@
                {
                        
m_expression->appendOpCode(XPathExpression::eELEMWILDCARD);
                }
  +             else if (isNodeTest(m_token) == false)
  +             {
  +                     error("Expected node test!");
  +             }
                else
                {
                        if (axisType == XPathExpression::eFROM_NAMESPACE)
  @@ -2455,6 +2460,65 @@
   
   
   
  +bool
  +XPathProcessorImpl::isAxis(const XalanDOMString&     theToken)
  +{
  +     const XalanDOMString::size_type         theLength = length(theToken);
  +
  +     if (theLength == 0)
  +     {
  +             return false;
  +     }
  +     else if (theLength == 1 &&
  +                      charAt(theToken, 0) == XalanUnicode::charCommercialAt)
  +     {
  +             return true;
  +     }
  +     else
  +     {
  +             const AxisNamesMapType::const_iterator  i =
  +                     s_axisNames.find(theToken);
  +
  +             if (i != s_axisNames.end())
  +             {
  +                     return true;
  +             }
  +             else
  +             {
  +                     return false;
  +             }
  +     }
  +}
  +
  +
  +
  +bool
  +XPathProcessorImpl::isNodeTest(const XalanDOMString& theToken)
  +{
  +     const XalanDOMString::size_type         theLength = length(theToken);
  +
  +     if (theLength == 0)
  +     {
  +             return false;
  +     }
  +     else if (theLength == 1 &&
  +                      charAt(theToken, 0) == XalanUnicode::charAsterisk)
  +     {
  +             return true;
  +     }
  +     else if (charAt(theToken, 0) == XalanUnicode::charLowLine ||
  +                      XalanXMLChar::isLetter(charAt(theToken, 0)) == true)
  +     {
  +             return true;
  +     }
  +     else
  +     {
  +             return false;
  +     }
  +}
  +
  +
  +
   void
   XPathProcessorImpl::initializeKeywordsTable(KeywordsMapType& /* theKeywords 
*/)
   {
  @@ -2540,6 +2604,10 @@
   static XalanDOMString        s_attributeString;
   
   static XalanDOMString        s_childString;
  +
  +
  +const XalanDOMString XPathProcessorImpl::s_emptyString;
  +
   
   
   const XalanDOMString&        XPathProcessorImpl::s_functionIDString = 
::s_functionIDString;
  
  
  
  1.18      +21 -1     xml-xalan/c/src/XPath/XPathProcessorImpl.hpp
  
  Index: XPathProcessorImpl.hpp
  ===================================================================
  RCS file: /home/cvs/xml-xalan/c/src/XPath/XPathProcessorImpl.hpp,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- XPathProcessorImpl.hpp    2001/07/12 04:35:50     1.17
  +++ XPathProcessorImpl.hpp    2001/11/26 23:16:02     1.18
  @@ -355,7 +355,7 @@
         * Retrieve the next token from the command and
         * store it in m_token string.
         */
  -     XalanDOMString
  +     const XalanDOMString&
        getTokenRelative(int    theOffset) const;
   
        /**
  @@ -390,6 +390,24 @@
        isCurrentLiteral() const;
   
        /**
  +      * Determine if the token is an axis
  +      *
  +      * @param theToken The token to test
  +      * @return true if the token is a valid axis, false if not.
  +      */
  +     static bool
  +     isAxis(const XalanDOMString&    theToken);
  +
  +     /**
  +      * Determine if the token could be a node test
  +      *
  +      * @param theToken The token to test
  +      * @return true if the token is a valid node test, false if not.
  +      */
  +     static bool
  +     isNodeTest(const XalanDOMString&        theToken);
  +
  +     /**
         * Throw an exception using the provided message text.
         */
        void
  @@ -805,6 +823,8 @@
        {
                TARGETEXTRA = 10000
        };
  +
  +     static const XalanDOMString             s_emptyString;
   
        // This shouldn't really be here, since it duplicates a string that is 
part
        // of the information that is maintained by the class 
XPathFunctionTable,
  
  
  

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

Reply via email to