You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@wicket.apache.org by mg...@apache.org on 2012/04/13 13:48:34 UTC

[1/2] git commit: WICKET-4494 HtmlHandler wrongly handles tags not requiring closed tags if the markup does not have "top" level tag

Updated Branches:
  refs/heads/master e6582c529 -> 35843c196


WICKET-4494 HtmlHandler wrongly handles tags not requiring closed tags if the markup does not have "top" level tag


Project: http://git-wip-us.apache.org/repos/asf/wicket/repo
Commit: http://git-wip-us.apache.org/repos/asf/wicket/commit/35843c19
Tree: http://git-wip-us.apache.org/repos/asf/wicket/tree/35843c19
Diff: http://git-wip-us.apache.org/repos/asf/wicket/diff/35843c19

Branch: refs/heads/master
Commit: 35843c19628b0346acec2867cc88fbabb81e8a4f
Parents: 66ff952
Author: Martin Tzvetanov Grigorov <mg...@apache.org>
Authored: Fri Apr 13 14:47:12 2012 +0300
Committer: Martin Tzvetanov Grigorov <mg...@apache.org>
Committed: Fri Apr 13 14:48:19 2012 +0300

----------------------------------------------------------------------
 .../wicket/markup/parser/filter/HtmlHandler.java   |    1 +
 .../markup/parser/filter/CustomMarkupLabel.java    |   91 +++++++++++++++
 ...ynamicMarkupPageWithNonClosedTags_expected.html |    1 +
 .../markup/parser/filter/HtmlHandlerTest.java      |   62 ++++++++++
 4 files changed, 155 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/wicket/blob/35843c19/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/HtmlHandler.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/HtmlHandler.java b/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/HtmlHandler.java
index b45ed7c..440e5bc 100644
--- a/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/HtmlHandler.java
+++ b/wicket-core/src/main/java/org/apache/wicket/markup/parser/filter/HtmlHandler.java
@@ -78,6 +78,7 @@ public final class HtmlHandler extends AbstractMarkupFilter
 			if (!requiresCloseTag(top.getName()))
 			{
 				stack.pop();
+				top.setHasNoCloseTag(true);
 			}
 			else
 			{

http://git-wip-us.apache.org/repos/asf/wicket/blob/35843c19/wicket-core/src/test/java/org/apache/wicket/markup/parser/filter/CustomMarkupLabel.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/parser/filter/CustomMarkupLabel.java b/wicket-core/src/test/java/org/apache/wicket/markup/parser/filter/CustomMarkupLabel.java
new file mode 100644
index 0000000..0209076
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/parser/filter/CustomMarkupLabel.java
@@ -0,0 +1,91 @@
+package org.apache.wicket.markup.parser.filter;
+
+import java.nio.charset.Charset;
+
+import org.apache.wicket.Component;
+import org.apache.wicket.MarkupContainer;
+import org.apache.wicket.markup.ComponentTag;
+import org.apache.wicket.markup.IMarkupCacheKeyProvider;
+import org.apache.wicket.markup.IMarkupFragment;
+import org.apache.wicket.markup.IMarkupResourceStreamProvider;
+import org.apache.wicket.markup.MarkupException;
+import org.apache.wicket.markup.MarkupStream;
+import org.apache.wicket.markup.html.panel.AbstractMarkupSourcingStrategy;
+import org.apache.wicket.markup.html.panel.IMarkupSourcingStrategy;
+import org.apache.wicket.util.resource.IResourceStream;
+import org.apache.wicket.util.resource.StringResourceStream;
+
+/**
+ * https://issues.apache.org/jira/browse/WICKET-4494
+ * @see HtmlHandlerTest
+ */
+public class CustomMarkupLabel
+		extends MarkupContainer
+		implements IMarkupCacheKeyProvider, IMarkupResourceStreamProvider
+{
+	private static final String SAMPLE_MARKUP = "<img alt='logo' src='logo.png'><br>Some text<br>Some more text";
+	
+	public CustomMarkupLabel(final String id)
+	{
+		super(id); 
+	}
+
+	@Override
+	protected IMarkupSourcingStrategy newMarkupSourcingStrategy()
+	{
+		return new MyMarkupSourcingStrategy(this);
+	}
+	
+	public IResourceStream getMarkupResourceStream(MarkupContainer container, Class<?> containerClass)
+	{
+		// the markup is loaded from database in our real application
+		StringResourceStream res = new StringResourceStream(SAMPLE_MARKUP);
+		res.setCharset(Charset.forName("UTF-8"));
+		return res;
+	}
+
+	public String getCacheKey(MarkupContainer container, Class<?> containerClass)
+	{
+		return null;
+	}
+	
+	//
+	// custom markup sourcing strategy
+	//
+	
+	private static class MyMarkupSourcingStrategy extends AbstractMarkupSourcingStrategy
+	{
+		private final CustomMarkupLabel markupProvider;
+
+		public MyMarkupSourcingStrategy(final CustomMarkupLabel markupProvider)
+		{
+			this.markupProvider = markupProvider;
+		}
+
+		@Override
+		public void onComponentTagBody(Component component, MarkupStream markupStream, ComponentTag openTag)
+		{
+			super.onComponentTagBody(component, markupStream, openTag);
+			// 
+			MarkupStream stream = new MarkupStream(getMarkup((MarkupContainer)component, null));
+			component.onComponentTagBody(stream, openTag);
+		}
+
+		@Override
+		public IMarkupFragment getMarkup(final MarkupContainer container, final Component child)
+		{
+			IMarkupFragment markup = markupProvider.getAssociatedMarkup();
+			if (markup == null)
+			{
+				throw new MarkupException("The EntityText has no markup!");
+			}
+			//
+			if (child == null)
+			{
+				return markup;
+			}
+			// search for the child insight the fragment markup
+			return markup.find(child.getId());
+		}
+	}
+}

http://git-wip-us.apache.org/repos/asf/wicket/blob/35843c19/wicket-core/src/test/java/org/apache/wicket/markup/parser/filter/DynamicMarkupPageWithNonClosedTags_expected.html
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/parser/filter/DynamicMarkupPageWithNonClosedTags_expected.html b/wicket-core/src/test/java/org/apache/wicket/markup/parser/filter/DynamicMarkupPageWithNonClosedTags_expected.html
new file mode 100644
index 0000000..462aa7c
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/parser/filter/DynamicMarkupPageWithNonClosedTags_expected.html
@@ -0,0 +1 @@
+<html><body><span wicket:id="label"><img alt="logo" src="../logo.png"><br>Some text<br>Some more text</span></body></html>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/wicket/blob/35843c19/wicket-core/src/test/java/org/apache/wicket/markup/parser/filter/HtmlHandlerTest.java
----------------------------------------------------------------------
diff --git a/wicket-core/src/test/java/org/apache/wicket/markup/parser/filter/HtmlHandlerTest.java b/wicket-core/src/test/java/org/apache/wicket/markup/parser/filter/HtmlHandlerTest.java
new file mode 100644
index 0000000..7d63fb1
--- /dev/null
+++ b/wicket-core/src/test/java/org/apache/wicket/markup/parser/filter/HtmlHandlerTest.java
@@ -0,0 +1,62 @@
+/*
+ * 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.filter;
+
+import org.apache.wicket.MarkupContainer;
+import org.apache.wicket.WicketTestCase;
+import org.apache.wicket.markup.IMarkupResourceStreamProvider;
+import org.apache.wicket.markup.html.WebPage;
+import org.apache.wicket.util.resource.IResourceStream;
+import org.apache.wicket.util.resource.StringResourceStream;
+import org.junit.Test;
+
+/**
+ * @since 1.5.6
+ */
+public class HtmlHandlerTest extends WicketTestCase
+{
+	/**
+	 * https://issues.apache.org/jira/browse/WICKET-4494
+	 *
+	 * Asserts that a page which markup is loaded dynamically with IMarkupResourceStreamProvider
+	 * and the the loaded markup has HtmlHandler#doesNotRequireCloseTag tags loads OK
+	 *
+	 * @throws Exception
+	 */
+	@Test
+	public void loadMarkupWithNonClosedTagsDynamically() throws Exception
+	{
+		CustomMarkupPage page = new CustomMarkupPage();
+		tester.executeTest(HtmlHandlerTest.class, page, "DynamicMarkupPageWithNonClosedTags_expected.html");
+	}
+
+	/**
+	 * The test page for #loadMarkupWithNonClosedTagsDynamically()
+	 */
+	private static class CustomMarkupPage extends WebPage implements IMarkupResourceStreamProvider
+	{
+		private CustomMarkupPage()
+		{
+			add(new CustomMarkupLabel("label"));
+		}
+
+		public IResourceStream getMarkupResourceStream(MarkupContainer container, Class<?> containerClass)
+		{
+			return new StringResourceStream("<html><body><span wicket:id='label'></span></body></html>");
+		}
+	}
+}