xalan-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From zong...@apache.org
Subject cvs commit: xml-xalan/java/src/org/apache/xml/dtm/ref/sax2dtm SAX2DTM2.java
Date Thu, 27 Jan 2005 15:28:02 GMT
zongaro     2005/01/27 07:28:02

  Modified:    java/src/org/apache/xml/dtm/ref/sax2dtm SAX2DTM2.java
  Log:
  Two part fix for Jira bug report XALANJ-1888.
  
  1) It is possible for the characters SAX event to specify a length of zero.
  Text nodes should not be created in such situations.  Changed the
  charactersFlush method to guard against this case.
  
  2) Made a defensive change to references to m_dataOrQName.  If the value in
  this vector is to be interpreted as an index into m_data, it is stored as a
  negative value (via calls to addNode).  However, most references to elements of
  m_dataOrQName were checking whether the value was non-positive, treating a
  value of zero as an index into m_data as well.  The zeroth entry into m_data is
  an invalid entry.
  The fix to charactersFlush described above should ensure that zero is never
  stored in m_dataOrQName, but I thought it was just as well to duplicate the
  interpretation used in storing values in m_dataOrQName.
  
  Reviewed by Morris Kwan (mkwan () ca ! ibm ! com)
  
  Revision  Changes    Path
  1.15      +30 -29    xml-xalan/java/src/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM2.java
  
  Index: SAX2DTM2.java
  ===================================================================
  RCS file: /home/cvs/xml-xalan/java/src/org/apache/xml/dtm/ref/sax2dtm/SAX2DTM2.java,v
  retrieving revision 1.14
  retrieving revision 1.15
  diff -u -r1.14 -r1.15
  --- SAX2DTM2.java	24 Jan 2005 00:34:36 -0000	1.14
  +++ SAX2DTM2.java	27 Jan 2005 15:28:02 -0000	1.15
  @@ -1,5 +1,5 @@
   /*
  - * Copyright 1999-2004 The Apache Software Foundation.
  + * Copyright 1999-2005 The Apache Software Foundation.
    *
    * Licensed under the Apache License, Version 2.0 (the "License");
    * you may not use this file except in compliance with the License.
  @@ -2399,31 +2399,32 @@
           doStrip = m_chars.isWhitespace(m_textPendingStart, length);
         }
   
  -      if (doStrip)
  +      if (doStrip) {
           m_chars.setLength(m_textPendingStart);  // Discard accumulated text
  -      else
  -      {
  -        // If the offset and length do not exceed the given limits
  -        // (offset < 2^21 and length < 2^10), then save both the offset
  -        // and length in a bitwise encoded value.
  -        if (length <= TEXT_LENGTH_MAX && m_textPendingStart <= TEXT_OFFSET_MAX)
  -        {
  -          m_previous = addNode(m_coalescedTextType, DTM.TEXT_NODE,
  +      } else {
  +        // Guard against characters/ignorableWhitespace events that
  +        // contained no characters.  They should not result in a node.
  +        if (length > 0) {
  +          // If the offset and length do not exceed the given limits
  +          // (offset < 2^21 and length < 2^10), then save both the offset
  +          // and length in a bitwise encoded value.
  +          if (length <= TEXT_LENGTH_MAX
  +                  && m_textPendingStart <= TEXT_OFFSET_MAX) {
  +            m_previous = addNode(m_coalescedTextType, DTM.TEXT_NODE,
                                m_parents.peek(), m_previous,
                                length + (m_textPendingStart << TEXT_LENGTH_BITS),
                                false);
   
  -        }
  -        else
  -        {
  -          // Store the offset and length in the m_data array if one of them
  -          // exceeds the given limits. Use a negative dataIndex as an indication.
  -          int dataIndex = m_data.size();
  -          m_previous = addNode(m_coalescedTextType, DTM.TEXT_NODE,
  -                             m_parents.peek(), m_previous, -dataIndex, false);
  +          } else {
  +            // Store offset and length in the m_data array if one exceeds 
  +            // the given limits. Use a negative dataIndex as an indication.
  +            int dataIndex = m_data.size();
  +            m_previous = addNode(m_coalescedTextType, DTM.TEXT_NODE,
  +                               m_parents.peek(), m_previous, -dataIndex, false);
   
  -          m_data.addElement(m_textPendingStart);
  -          m_data.addElement(length);
  +            m_data.addElement(m_textPendingStart);
  +            m_data.addElement(length);
  +          }
           }
         }
   
  @@ -2791,7 +2792,7 @@
   	  if (type == DTM.TEXT_NODE || type == DTM.CDATA_SECTION_NODE)
   	  {
   	    int dataIndex = m_dataOrQName.elementAt(identity);
  -	    if (dataIndex > 0)
  +	    if (dataIndex >= 0)
   	    {
   	      if (-1 == offset)
   	      {
  @@ -2830,7 +2831,7 @@
       else if (DTM.TEXT_NODE == type || DTM.CDATA_SECTION_NODE == type)
       {
         int dataIndex = m_dataOrQName.elementAt(identity);
  -      if (dataIndex > 0)
  +      if (dataIndex >= 0)
         {
         	if (m_xstrf != null)
         	  return m_xstrf.newstr(m_chars, dataIndex >>> TEXT_LENGTH_BITS,
  @@ -2904,7 +2905,7 @@
   	  if (type == DTM.TEXT_NODE || type == DTM.CDATA_SECTION_NODE)
   	  {
   	    int dataIndex = m_dataOrQName.elementAt(identity);
  -	    if (dataIndex > 0)
  +	    if (dataIndex >= 0)
   	    {
   	      if (-1 == offset)
   	      {
  @@ -2940,7 +2941,7 @@
       else if (DTM.TEXT_NODE == type || DTM.CDATA_SECTION_NODE == type)
       {
         int dataIndex = m_dataOrQName.elementAt(identity);
  -      if (dataIndex > 0)
  +      if (dataIndex >= 0)
         {
         	return m_chars.getString(dataIndex >>> TEXT_LENGTH_BITS,
         	                          dataIndex & TEXT_LENGTH_MAX);
  @@ -2977,7 +2978,7 @@
       if ((_exptype2(child) == DTM.TEXT_NODE) && (_nextsib2(child) == DTM.NULL))
       {
         int dataIndex = m_dataOrQName.elementAt(child);
  -      if (dataIndex > 0)
  +      if (dataIndex >= 0)
           return m_chars.getString(dataIndex >>> TEXT_LENGTH_BITS, dataIndex &
TEXT_LENGTH_MAX);
         else
           return m_chars.getString(m_data.elementAt(-dataIndex),
  @@ -3036,7 +3037,7 @@
   	  {
   	    int dataIndex = m_dataOrQName.elementAt(identity);
   
  -	    if (dataIndex > 0)
  +	    if (dataIndex >= 0)
   	    {
   	      if (-1 == offset)
   	      {
  @@ -3072,7 +3073,7 @@
       {
         int dataIndex = m_dataOrQName.elementAt(identity);
   
  -      if (dataIndex > 0)
  +      if (dataIndex >= 0)
         {
         	if (normalize)
         	  m_chars.sendNormalizedSAXcharacters(ch, dataIndex >>> TEXT_LENGTH_BITS,
  @@ -3167,7 +3168,7 @@
       {
           if (nodeID != DTM.NULL) {
         	    int dataIndex = m_dataOrQName.elementAt(nodeID);
  -            if (dataIndex > 0) {
  +            if (dataIndex >= 0) {
                   m_chars.sendSAXcharacters(handler,
                                             dataIndex >>> TEXT_LENGTH_BITS,
                                             dataIndex & TEXT_LENGTH_MAX);
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: xalan-cvs-unsubscribe@xml.apache.org
For additional commands, e-mail: xalan-cvs-help@xml.apache.org


Mime
View raw message