ant-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From j..@apache.org
Subject svn commit: r374544 - in /ant/core/trunk: WHATSNEW src/main/org/apache/tools/ant/types/FilterSet.java src/testcases/org/apache/tools/ant/types/FilterSetTest.java
Date Thu, 02 Feb 2006 23:49:14 GMT
Author: jkf
Date: Thu Feb  2 15:48:59 2006
New Revision: 374544

URL: http://svn.apache.org/viewcvs?rev=374544&view=rev
Log:
pr38465 improved recursion detection to allow the same token on one line multiple times.

Modified:
    ant/core/trunk/WHATSNEW
    ant/core/trunk/src/main/org/apache/tools/ant/types/FilterSet.java
    ant/core/trunk/src/testcases/org/apache/tools/ant/types/FilterSetTest.java

Modified: ant/core/trunk/WHATSNEW
URL: http://svn.apache.org/viewcvs/ant/core/trunk/WHATSNEW?rev=374544&r1=374543&r2=374544&view=diff
==============================================================================
--- ant/core/trunk/WHATSNEW (original)
+++ ant/core/trunk/WHATSNEW Thu Feb  2 15:48:59 2006
@@ -4,6 +4,9 @@
 Changes that could break older environments:
 --------------------------------------------
 
+* Improved recursion detection for lines with multiple matches of same token on one single
line.
+  Bugzilla report 38456.
+
 * Task will now log correctly even if no project is set. 
   Bugzilla report 38458.
 

Modified: ant/core/trunk/src/main/org/apache/tools/ant/types/FilterSet.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/main/org/apache/tools/ant/types/FilterSet.java?rev=374544&r1=374543&r2=374544&view=diff
==============================================================================
--- ant/core/trunk/src/main/org/apache/tools/ant/types/FilterSet.java (original)
+++ ant/core/trunk/src/main/org/apache/tools/ant/types/FilterSet.java Thu Feb  2 15:48:59
2006
@@ -179,6 +179,8 @@
     private OnMissing onMissingFiltersFile = OnMissing.FAIL;
     private boolean readingFiles = false;
 
+    private int recurseDepth = 0;
+
     /**
      * List of ordered filters and filter files.
      */
@@ -383,7 +385,6 @@
      * @return      The input string after token replacement.
      */
     public synchronized String replaceTokens(String line) {
-        passedTokens = null; // reset for new line
         return iReplaceTokens(line);
     }
 
@@ -506,7 +507,7 @@
                 String token = null;
                 String value = null;
 
-                do {
+                while (index > -1) {
                     //can't have zero-length token
                     int endIndex = line.indexOf(endToken,
                         index + beginToken.length() + 1);
@@ -532,7 +533,8 @@
                         b.append(beginToken);
                         i = index + beginToken.length();
                     }
-                } while ((index = line.indexOf(beginToken, i)) > -1);
+                    index = line.indexOf(beginToken, i);
+                }
 
                 b.append(line.substring(i));
                 return b.toString();
@@ -555,9 +557,10 @@
         throws BuildException {
         String beginToken = getBeginToken();
         String endToken = getEndToken();
-        if (passedTokens == null) {
+        if (recurseDepth == 0) {
             passedTokens = new Vector();
         }
+        recurseDepth++;
         if (passedTokens.contains(parent) && !duplicateToken) {
             duplicateToken = true;
             System.out.println(
@@ -565,6 +568,7 @@
                 + passedTokens.toString() + "\nProblem token : " + beginToken
                 + parent + endToken + " called from " + beginToken
                 + passedTokens.lastElement().toString() + endToken);
+            recurseDepth--;
             return parent;
         }
         passedTokens.addElement(parent);
@@ -582,6 +586,7 @@
                 }
             }
         }
+        recurseDepth--;
         return value;
     }
 

Modified: ant/core/trunk/src/testcases/org/apache/tools/ant/types/FilterSetTest.java
URL: http://svn.apache.org/viewcvs/ant/core/trunk/src/testcases/org/apache/tools/ant/types/FilterSetTest.java?rev=374544&r1=374543&r2=374544&view=diff
==============================================================================
--- ant/core/trunk/src/testcases/org/apache/tools/ant/types/FilterSetTest.java (original)
+++ ant/core/trunk/src/testcases/org/apache/tools/ant/types/FilterSetTest.java Thu Feb  2
15:48:59 2006
@@ -113,6 +113,23 @@
         assertEquals(result, fs.replaceTokens(line));
     }
 
+    public void testNonInfiniteRecursiveMultipleOnSingleLine() {
+        FilterSet filters = new FilterSet();
+
+        filters.setBeginToken("<");
+        filters.setEndToken(">");
+
+        filters.addFilter("ul", "<itemizedlist>");
+        filters.addFilter("/ul", "</itemizedList>");
+        filters.addFilter("li", "<listitem>");
+        filters.addFilter("/li", "</listitem>");
+
+        String result = "<itemizedlist><listitem>Item 1</listitem> <listitem>Item
2</listitem></itemizedList>";
+        String line = "<ul><li>Item 1</li> <li>Item 2</li></ul>";
+
+        assertEquals(result, filters.replaceTokens(line));
+    }
+    
     public void testNestedFilterSets() {
         executeTarget("test-nested-filtersets");
 



---------------------------------------------------------------------
To unsubscribe, e-mail: dev-unsubscribe@ant.apache.org
For additional commands, e-mail: dev-help@ant.apache.org


Mime
View raw message