Author: jalkanen
Date: Sat Aug 16 03:39:47 2008
New Revision: 686473

URL: http://svn.apache.org/viewvc?rev=686473&view=rev
Log:
JSPWIKI-307: Needed to rewrite the encodeHTMLEntities() method to properly 
handle names with ampersands.

Modified:
    incubator/jspwiki/trunk/ChangeLog
    incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java
    
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/parser/JSPWikiMarkupParser.java
    
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/parser/JSPWikiMarkupParserTest.java

Modified: incubator/jspwiki/trunk/ChangeLog
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/ChangeLog?rev=686473&r1=686472&r2=686473&view=diff
==============================================================================
--- incubator/jspwiki/trunk/ChangeLog (original)
+++ incubator/jspwiki/trunk/ChangeLog Sat Aug 16 03:39:47 2008
@@ -1,3 +1,16 @@
+2008-08-16  Janne Jalkanen <[EMAIL PROTECTED]>
+
+        * 2.7.0-alpha-19
+        
+        * JSPWIKI-315: Fixed issues with upper/lowercase filtering in 
+        AttachmentManager
+        
+        * JSPWIKI-325: Patch from Harry to sort out plugin parameters and 
their 
+        javadocs.
+        
+        * JSPWIKI-307: Pages with & in their names were not being parsed 
properly 
+        in links.
+
 2008-08-15  Harry Metske <[EMAIL PROTECTED]>
 
         * 2.7.0-alpha-18

Modified: incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java?rev=686473&r1=686472&r2=686473&view=diff
==============================================================================
--- incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java (original)
+++ incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/Release.java Sat Aug 16 
03:39:47 2008
@@ -77,7 +77,7 @@
      *  <p>
      *  If the build identifier is empty, it is not added.
      */
-    public static final String     BUILD         = "18";
+    public static final String     BUILD         = "19";
     
     /**
      *  This is the generic version string you should use

Modified: 
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/parser/JSPWikiMarkupParser.java
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/parser/JSPWikiMarkupParser.java?rev=686473&r1=686472&r2=686473&view=diff
==============================================================================
--- 
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/parser/JSPWikiMarkupParser.java 
(original)
+++ 
incubator/jspwiki/trunk/src/com/ecyrd/jspwiki/parser/JSPWikiMarkupParser.java 
Sat Aug 16 03:39:47 2008
@@ -918,19 +918,47 @@
             }
             else if( ch == '&' )
             {
-                for( int j = (i < buf.length()-1 ) ? i+1 : i; j < 
buf.length(); j++ )
+                //
+                //  If the following is an XML entity reference (&#.*;) we'll
+                //  leave it as it is; otherwise we'll replace it with an &amp;
+                //
+                
+                boolean isEntity = false;
+                StringBuilder entityBuf = new StringBuilder();
+                
+                if( i < buf.length() -1 )
                 {
-                    int ch2 = buf.charAt(j);
-                    if( ch2 == ';' )
+                    for( int j = i; j < buf.length(); j++ )
                     {
-                        tmpBuf.append(ch);
-                        break;
-                    }
-                    if( ch2 != '#' && !Character.isLetterOrDigit( (char)ch2) )
-                    {
-                        tmpBuf.append("&amp;"); break;
+                        char ch2 = buf.charAt(j);
+                        
+                        if( Character.isLetterOrDigit( ch2 ) || (ch2 == '#' && 
j == i+1) || ch2 == ';' || ch2 == '&' )
+                        {
+                            entityBuf.append(ch2);
+                            
+                            if( ch2 == ';' )
+                            {
+                                isEntity = true;
+                                break;
+                            }
+                        }
+                        else
+                        {
+                            break;
+                        }
                     }
                 }
+                
+                if( isEntity ) 
+                {
+                    tmpBuf.append( entityBuf );
+                    i = i + entityBuf.length() - 1;
+                }
+                else 
+                {
+                    tmpBuf.append("&amp;");
+                }
+                
             }
             else
             {

Modified: 
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/parser/JSPWikiMarkupParserTest.java
URL: 
http://svn.apache.org/viewvc/incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/parser/JSPWikiMarkupParserTest.java?rev=686473&r1=686472&r2=686473&view=diff
==============================================================================
--- 
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/parser/JSPWikiMarkupParserTest.java
 (original)
+++ 
incubator/jspwiki/trunk/tests/com/ecyrd/jspwiki/parser/JSPWikiMarkupParserTest.java
 Sat Aug 16 03:39:47 2008
@@ -2611,7 +2611,27 @@
 
         assertEquals( "<a class=\"external\" 
href=\"http://www.host.com/du=&quot;&gt; &lt;img src=&quot;foobar&quot; 
onerror=&quot;alert(document.cookie)&quot;/&gt;\">http://www.host.com/du=&quot;&gt;
 &lt;img src=&quot;foobar&quot; 
onerror=&quot;alert(document.cookie)&quot;/&gt;</a>", dst );
     }
+    
+    public void testAmpersand1() throws Exception
+    {
+        newPage( "Foo&Bar" );
+        String src = "[Foo&Bar]";
+
+        String dst = translate(src);
+
+        assertEquals( "<a class=\"wikipage\" 
href=\"/Wiki.jsp?page=Foo%26Bar\">Foo&amp;Bar</a>", dst );
+    }
 
+    public void testAmpersand2() throws Exception
+    {
+        newPage( "Foo & Bar" );
+        String src = "[Foo & Bar]";
+
+        String dst = translate(src);
+
+        assertEquals( "<a class=\"wikipage\" 
href=\"/Wiki.jsp?page=Foo%20%26%20Bar\">Foo &amp; Bar</a>", dst );
+    }
+    
     // This is a random find: the following page text caused an eternal loop 
in V2.0.x.
     private static final String brokenPageText =
         "Please ''check [RecentChanges].\n" +


Reply via email to