You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@wicket.apache.org by Martijn Dashorst <ma...@gmail.com> on 2009/02/18 11:55:17 UTC
Re: svn commit: r745247 - in /wicket/trunk/wicket/src:
main/java/org/apache/wicket/markup/ test/java/org/apache/wicket/markup/parser/
Is this change pushable to 1.3.x too? Or does this break possibly
something? I'm willing to do the legwork, just wanted to make sure
this can be applied to 1.3.x...
Martijn
On Tue, Feb 17, 2009 at 9:38 PM, <jd...@apache.org> wrote:
> Author: jdonnerstag
> Date: Tue Feb 17 20:38:15 2009
> New Revision: 745247
>
> URL: http://svn.apache.org/viewvc?rev=745247&view=rev
> Log:
> fixed wicket-2105: Stripping comments causes StackOverflowError in XmlPullParser
>
> Added:
> wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/HomePage.html
> wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/HomePage.java
> wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/SignInPanel.html
> wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/SignInPanel.java
> wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/TestHomePage.java
> Modified:
> wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MarkupParser.java
>
> Modified: wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MarkupParser.java
> URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MarkupParser.java?rev=745247&r1=745246&r2=745247&view=diff
> ==============================================================================
> --- wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MarkupParser.java (original)
> +++ wicket/trunk/wicket/src/main/java/org/apache/wicket/markup/MarkupParser.java Tue Feb 17 20:38:15 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;
> @@ -223,7 +223,7 @@
> * beforeFilter not found than append to the end
> */
> public final void appendMarkupFilter(final IMarkupFilter filter,
> - final Class< ? extends IMarkupFilter> beforeFilter)
> + final Class<? extends IMarkupFilter> beforeFilter)
> {
> if ((beforeFilter == null) || (markupFilterChain == null))
> {
> @@ -478,15 +478,17 @@
> }
>
> /**
> - * Remove all comment sections (<!-- .. -->) 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 (<!-- .. -->) 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)
> {
> @@ -496,6 +498,11 @@
> if (pos2 != -1)
> {
> final String comment = rawMarkup.substring(pos1 + 4, pos2);
> +
> + // 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
> if (CONDITIONAL_COMMENT.matcher(comment).matches() == false)
> {
> buf.append(rawMarkup.substring(0, pos1));
>
> Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/HomePage.html
> URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/HomePage.html?rev=745247&view=auto
> ==============================================================================
> --- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/HomePage.html (added)
> +++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/HomePage.html Tue Feb 17 20:38:15 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/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/HomePage.java
> URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/HomePage.java?rev=745247&view=auto
> ==============================================================================
> --- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/HomePage.java (added)
> +++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/HomePage.java Tue Feb 17 20:38:15 2009
> @@ -0,0 +1,43 @@
> +/*
> + * 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 HomePage extends WebPage
> +{
> + private static final long serialVersionUID = 1L;
> +
> + /**
> + * Construct.
> + *
> + * @param parameters
> + */
> + public HomePage(final PageParameters parameters)
> + {
> + add(new Label("pageTitle", "PageTitle"));
> + add(new FeedbackPanel("feedback"));
> + add(new SignInPanel("signInPanel"));
> + add(new Label("version", "1.0"));
> + }
> +}
>
> Added: wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/SignInPanel.html
> URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/SignInPanel.html?rev=745247&view=auto
> ==============================================================================
> --- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/SignInPanel.html (added)
> +++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/SignInPanel.html Tue Feb 17 20:38:15 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/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/SignInPanel.java
> URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/SignInPanel.java?rev=745247&view=auto
> ==============================================================================
> --- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/SignInPanel.java (added)
> +++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/SignInPanel.java Tue Feb 17 20:38:15 2009
> @@ -0,0 +1,58 @@
> +/*
> + * 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 SignInPanel extends Panel
> +{
> + private static final long serialVersionUID = 1L;
> +
> + /**
> + * Construct.
> + *
> + * @param id
> + */
> + public SignInPanel(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("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/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/TestHomePage.java
> URL: http://svn.apache.org/viewvc/wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/TestHomePage.java?rev=745247&view=auto
> ==============================================================================
> --- wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/TestHomePage.java (added)
> +++ wicket/trunk/wicket/src/test/java/org/apache/wicket/markup/parser/TestHomePage.java Tue Feb 17 20:38:15 2009
> @@ -0,0 +1,50 @@
> +/*
> + * 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.util.tester.WicketTester;
> +
> +/**
> + *
> + */
> +public class TestHomePage extends TestCase
> +{
> + private WicketTester tester;
> +
> + @Override
> + public void setUp()
> + {
> + tester = new WicketTester();
> + }
> +
> + /**
> + * Wicket-2105
> + */
> + public void testRenderMyPage()
> + {
> + // start and render the test page
> + tester.startPage(HomePage.class);
> +
> + // assert rendered page class
> + tester.assertRenderedPage(HomePage.class);
> +
> + // assert rendered label component
> + tester.assertLabel("version", "1.0");
> + }
> +}
>
>
>
--
Become a Wicket expert, learn from the best: http://wicketinaction.com
Apache Wicket 1.3.5 is released
Get it now: http://www.apache.org/dyn/closer.cgi/wicket/1.3.
Re: svn commit: r745247 - in /wicket/trunk/wicket/src:
main/java/org/apache/wicket/markup/ test/java/org/apache/wicket/markup/parser/
Posted by Juergen Donnerstag <ju...@gmail.com>.
The actual change is simple: change the regex in MarkupParser. That
will fix it. There are some javadoc changes (ref to sun bug database
etc.) and the testcase which you might copy as well. I can not think
of any risk in applying the patch to 1.3 as well.
Juergen