Author: dashorst
Date: Fri Feb 20 22:38:20 2009
New Revision: 746396

URL: http://svn.apache.org/viewvc?rev=746396&view=rev
Log:
WICKET-2105: backported fix from Juergen. It took a while to get the test to 
fail, but on JDK 1.6 it did, and after the patch, the test succeeded.

Added:
    
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Page.html
    
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Page.java
    
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Panel.html
    
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Panel.java
    
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Test.java
Modified:
    
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/MarkupParser.java

Modified: 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/MarkupParser.java
URL: 
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/MarkupParser.java?rev=746396&r1=746395&r2=746396&view=diff
==============================================================================
--- 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/MarkupParser.java
 (original)
+++ 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/main/java/org/apache/wicket/markup/MarkupParser.java
 Fri Feb 20 22:38:20 2009
@@ -68,7 +68,7 @@
        private static final Logger log = 
LoggerFactory.getLogger(MarkupParser.class);
 
        /** Conditional comment section, which is NOT treated as a comment 
section */
-       private static final Pattern CONDITIONAL_COMMENT = 
Pattern.compile("\\[if .+\\]>(.|\n|\r)*<!\\[endif\\]");
+       private static final Pattern CONDITIONAL_COMMENT = 
Pattern.compile("\\[if .+\\]>((?s).*)<!\\[endif\\]");
 
        /** The XML parser to use */
        private final IXmlPullParser xmlParser;
@@ -195,6 +195,7 @@
         * @see #appendMarkupFilter(IMarkupFilter)
         * @deprecated since 1.3
         */
+       @Deprecated
        protected void initFilterChain()
        {
                throw new WicketRuntimeException("This method is no longer 
suppoert: since 1.3");
@@ -476,15 +477,17 @@
        }
 
        /**
-        * Remove all comment sections (&lt;!-- .. --&gt;) from the raw markup. 
For reasons I don't
-        * understand, the following regex <code>"<!--(.|\n|\r)*?-->"<code>
-        * causes a stack overflow in some circumstances (jdk 1.5)
-        *
+        * Remove all comment sections (&lt;!-- .. --&gt;) from the raw markup.
+        * 
         * @param rawMarkup
         * @return raw markup
         */
        private String removeComment(String rawMarkup)
        {
+               // For reasons I don't understand, the following regex 
<code>"<!--(.|\n|\r)*?-->"<code>
+               // causes a stack overflow in some circumstances (jdk 1.5)
+               // See 
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5050507
+               // See 
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6337993
                int pos1 = rawMarkup.indexOf("<!--");
                while (pos1 != -1)
                {
@@ -493,6 +496,11 @@
                        final AppendingStringBuffer buf = new 
AppendingStringBuffer(rawMarkup.length());
                        if (pos2 != -1)
                        {
+
+                               // See wicket-2105 for an example where this 
rather simple regex throws an exception
+                               // CONDITIONAL_COMMENT = Pattern.compile("\\[if 
.+\\]>(.|\n|\r)*<!\\[endif\\]");
+                               // See 
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=5050507
+                               // See 
http://bugs.sun.com/bugdatabase/view_bug.do?bug_id=6337993
                                final String comment = rawMarkup.substring(pos1 
+ 4, pos2);
                                if 
(CONDITIONAL_COMMENT.matcher(comment).matches() == false)
                                {

Added: 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Page.html
URL: 
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Page.html?rev=746396&view=auto
==============================================================================
--- 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Page.html
 (added)
+++ 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Page.html
 Fri Feb 20 22:38:20 2009
@@ -0,0 +1,33 @@
+<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" 
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd";>
+<html xmlns:wicket>
+<head>
+       <meta http-equiv="content-type" content="text/html; charset=UTF-8" />
+       <link rel="shortcut icon" href="assets/img/icons/favicon.ico">
+       <title wicket:id="pageTitle">EduArte</title>
+       
+       <link href="assets/css/base.css" rel="stylesheet" type="text/css"/>
+       <!--[if IE]>
+               <link href="assets/css/ie_only.css" rel="stylesheet" 
type="text/css"/>
+               <link href="assets/js/ie_only.js" rel="stylesheet" 
type="text/css"/>
+       <![endif]-->
+       <!--[if lt IE 7]>
+               <link href="assets/css/ie6_only.css" rel="stylesheet" 
type="text/css"/>
+       <![endif]-->
+       <script type="text/javascript" 
src="assets/js/yahoo-dom-event.js"></script>
+       <script type="text/javascript" 
src="assets/js/animation/animation.js"></script>
+       <script type="text/javascript" src="assets/js/widgets.js"></script>
+</head>
+<body class="loginPage" onload="doFocus();">
+
+<div id="loginBox">
+       <div class="loginTitle">
+               <div class="loginError" wicket:id="feedback">Uw gebruikersnaam 
of wachtwoord is onjuist.</div>
+       </div>
+       <div class="loginFormBox" wicket:id="signInPanel">
+               Login panel comes here
+       </div>
+       <div class="loginFooter">Versie <span wicket:id="version">0.1</span> - 
Powered by Topicus</div>
+</div>
+
+</body>
+</html>
\ No newline at end of file

Added: 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Page.java
URL: 
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Page.java?rev=746396&view=auto
==============================================================================
--- 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Page.java
 (added)
+++ 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Page.java
 Fri Feb 20 22:38:20 2009
@@ -0,0 +1,35 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.markup.parser;
+
+import org.apache.wicket.PageParameters;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.markup.html.basic.Label;
+import org.apache.wicket.markup.html.panel.FeedbackPanel;
+
+public class Wicket2105Page extends WebPage
+{
+       private static final long serialVersionUID = 1L;
+
+       public Wicket2105Page(final PageParameters parameters)
+       {
+               add(new Label("pageTitle", "PageTitle"));
+               add(new FeedbackPanel("feedback"));
+               add(new Wicket2105Panel("signInPanel"));
+               add(new Label("version", "1.0"));
+       }
+}

Added: 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Panel.html
URL: 
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Panel.html?rev=746396&view=auto
==============================================================================
--- 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Panel.html
 (added)
+++ 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Panel.html
 Fri Feb 20 22:38:20 2009
@@ -0,0 +1,121 @@
+<html xmlns:wicket>
+<head>
+<wicket:head>
+       <script type="text/javascript">
+       function doFocus()
+       {
+           if(document.getElementById('username').value == "")
+               document.getElementById('username').focus();
+           else
+           {
+               var arr=document.getElementById('loginForm').elements;
+               var i=0;
+               for(i;i<arr.length;i++)
+               {
+                       if(arr[i] && arr[i].type && arr[i].type=="password")
+                       {
+                               arr[i].focus();
+                               break;
+                       }
+               }
+           }
+    }
+       function getkey(e)
+       {
+               if (window.event)
+                       return window.event.keyCode;
+               else if (e)
+                       return e.which;
+               else
+                       return null;
+       }
+       </script>
+       <!--[if lt IE 7]>
+       <script type="text/javascript">
+               jQuery.noConflict();
+               
+               jQuery(document).ready(function(){
+                       jQuery("#loginForm").hide();
+                       jQuery("#continueLink").click(function(){
+                               jQuery("#ie6warn").hide();
+                               jQuery("#loginForm").show();
+                       });
+               });
+       </script>
+       <![endif]-->
+</wicket:head>
+</head>
+<body>
+<wicket:panel>
+       <form id="loginForm" method="post" wicket:id="signInForm">
+       <fieldset>
+       <table>
+               <tbody>
+                       <tr>
+                               <td>Gebruikersnaam</td>
+                               <td><input type="text" id="username" 
wicket:id="username" /></td>
+                       </tr>
+                       <tr>
+                               <td>Wachtwoord</td>
+                               <td><input type="password" name="password" 
wicket:id="password" /></td>
+                       </tr>
+                       <tr>
+                               <td>Domein</td>
+                               <td><select name="instelling" 
wicket:id="domain" onkeypress="if (getkey(event)==13) 
getElementById('loginForm').submit();">
+                                       <option>School 01</option>
+                                       <option>School 02</option>
+                                       <option>School 03</option>
+                               </select></td>
+                       </tr>
+                       <tr>
+                               <td></td>
+                               <td><input type="checkbox" class="checkbox" 
name="rememberme"
+                                       id="rememberme" wicket:id="rememberMe" 
/> <label for="rememberme">Bewaar mijn gegevens</label></td>
+                       </tr>
+                       <tr wicket:id="loginZonderTokenContainer">
+                               <td></td>
+                               <td>
+                                       <input type="checkbox" class="checkbox" 
name="loginZonderToken"
+                                       id="loginZonderToken" 
wicket:id="loginZonderToken" /> 
+                                       <label for="loginZonderToken">Inloggen 
zonder token</label>
+                               </td>
+                       </tr>
+                       <tr>
+                               <td></td>
+                               <td>
+                                       <div class="widget-button">
+                                               <a href="#" 
wicket:id="aanmelden" title="Aanmelden bij DBS">
+                                                       <span>Aanmelden</span>
+                                               </a>
+                                       </div>
+                                       <input type="submit" style="width:0px; 
height:0px; position:absolute; top:-300px;" tabIndex="-1"/>
+                               </td>
+                       </tr>
+               </tbody>
+       </table>
+       </fieldset>
+       </form>
+       <!--[if lt IE 7]>
+       <div id="ie6warn">
+               <div class="highlight">U gebruikt Internet Explorer 6 of ouder. 
Deze applicatie vereist functionaliteit die niet door deze browser ondersteund 
wordt.</div>
+               Het is aan te raden een van de volgende browsers te gebruiken: 
+               <table>
+                       <tr>
+                               <td class="unit_80"><a 
href="http://www.firefox.com"; id="firefoxlink" class="logolink"></a></td>
+                               <td class="unit_130"><a 
href="http://www.microsoft.com/ie"; id="ielink" class="logolink"></a></td>
+                               <td class="unit_80"><a 
href="http://www.opera.com"; id="operalink" class="logolink"></a></td>
+                               <td class="unit_130"><a 
href="http://www.apple.com/safari"; id="safarilink" class="logolink"></a></td>
+                       </tr>
+                       <tr class="browsernames">
+                               <td>Firefox 3</td>
+                               <td>Internet Explorer 7</td>
+                               <td>Opera 9.5</td>
+                               <td>Safari 3</td>
+                       </tr>
+               </table>
+               <div class="right">Klik <a href="#" id="continueLink">hier</a> 
om toch uw eigen browser te gebruiken.</div>
+       </div>
+       <![endif]-->
+</wicket:panel>
+</body>
+</html>

Added: 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Panel.java
URL: 
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Panel.java?rev=746396&view=auto
==============================================================================
--- 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Panel.java
 (added)
+++ 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Panel.java
 Fri Feb 20 22:38:20 2009
@@ -0,0 +1,54 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.markup.parser;
+
+import java.util.Arrays;
+
+import org.apache.wicket.markup.html.WebMarkupContainer;
+import org.apache.wicket.markup.html.form.CheckBox;
+import org.apache.wicket.markup.html.form.DropDownChoice;
+import org.apache.wicket.markup.html.form.Form;
+import org.apache.wicket.markup.html.form.PasswordTextField;
+import org.apache.wicket.markup.html.form.SubmitLink;
+import org.apache.wicket.markup.html.form.TextField;
+import org.apache.wicket.markup.html.panel.Panel;
+import org.apache.wicket.model.CompoundPropertyModel;
+import org.apache.wicket.util.value.ValueMap;
+
+/**
+ * @author dashorst
+ */
+public class Wicket2105Panel extends Panel
+{
+       private static final long serialVersionUID = 1L;
+
+       public Wicket2105Panel(String id)
+       {
+               super(id);
+               Form form = new Form("signInForm", new 
CompoundPropertyModel(new ValueMap()));
+               form.add(new TextField("username"));
+               form.add(new PasswordTextField("password"));
+               form.add(new DropDownChoice("domain", Arrays.asList(new 
Object[] { "Wicket", "Tapestry",
+                               "JSF", ".Net" })));
+               form.add(new CheckBox("rememberMe"));
+               form.add(new 
WebMarkupContainer("loginZonderTokenContainer").add(new CheckBox(
+                       "loginZonderToken")));
+               form.add(new SubmitLink("aanmelden"));
+               add(form);
+       }
+
+}

Added: 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Test.java
URL: 
http://svn.apache.org/viewvc/wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Test.java?rev=746396&view=auto
==============================================================================
--- 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Test.java
 (added)
+++ 
wicket/branches/wicket-1.3.x/jdk-1.4/wicket/src/test/java/org/apache/wicket/markup/parser/Wicket2105Test.java
 Fri Feb 20 22:38:20 2009
@@ -0,0 +1,65 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements.  See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License.  You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.wicket.markup.parser;
+
+import junit.framework.TestCase;
+
+import org.apache.wicket.protocol.http.WebApplication;
+import org.apache.wicket.util.tester.WicketTester;
+
+/**
+ * Simple test using the WicketTester
+ */
+public class Wicket2105Test extends TestCase
+{
+       private WicketTester tester;
+
+       @Override
+       public void setUp()
+       {
+               tester = new WicketTester(new WicketApplication());
+       }
+
+       public void testRenderMyPage()
+       {
+               // start and render the test page
+               tester.startPage(Wicket2105Page.class);
+
+               // assert rendered page class
+               tester.assertRenderedPage(Wicket2105Page.class);
+
+               // assert rendered label component
+               tester.assertLabel("version", "1.0");
+       }
+
+       private class WicketApplication extends WebApplication
+       {
+               @Override
+               protected void init()
+               {
+                       super.init();
+
+                       getMarkupSettings().setStripComments(true);
+               }
+
+               @Override
+               public Class getHomePage()
+               {
+                       return Wicket2105Page.class;
+               }
+       }
+}


Reply via email to