diff options
author | Frank Becker | 2013-02-17 18:41:44 +0000 |
---|---|---|
committer | Frank Becker | 2013-05-08 19:53:11 +0000 |
commit | 3abd816821095f39a02344f491fe3970983b897c (patch) | |
tree | 176386979fa862e7eb40953231bed3a6dae56ff8 | |
parent | 72f83ab66f447100770672a3556e1efdd88a798e (diff) | |
download | org.eclipse.mylyn.commons-3abd816821095f39a02344f491fe3970983b897c.tar.gz org.eclipse.mylyn.commons-3abd816821095f39a02344f491fe3970983b897c.tar.xz org.eclipse.mylyn.commons-3abd816821095f39a02344f491fe3970983b897c.zip |
399927: HtmlTag.isSelfTerminating does not identify tags without a space
before the '/' as self-terminating
Change-Id: I982a8151404f8e5d6ea52a8a9748ba5bd81bd8e3
Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=399927
3 files changed, 90 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/HtmlStreamTokenizer.java b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/HtmlStreamTokenizer.java index ccbf7898..a61b567b 100644 --- a/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/HtmlStreamTokenizer.java +++ b/org.eclipse.mylyn.commons.core/src/org/eclipse/mylyn/commons/core/HtmlStreamTokenizer.java @@ -205,6 +205,13 @@ public class HtmlStreamTokenizer { for (; i < s.length() && !Character.isWhitespace(s.charAt(i)); i++) { // just move forward } + + if (s.charAt(i - 1) == '/') { + tag.setSelfTerminating(true); + tag.setTagName(s.substring(start, i - 1)); + return; + } + tag.setTagName(s.substring(start, i)); for (; i < s.length() && Character.isWhitespace(s.charAt(i)); i++) { diff --git a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/core/HtmlStreamTokenizerTest.java b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/core/HtmlStreamTokenizerTest.java new file mode 100644 index 00000000..fad64e02 --- /dev/null +++ b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/core/HtmlStreamTokenizerTest.java @@ -0,0 +1,81 @@ +/******************************************************************************* + * Copyright (c) 2013 Frank Becker and others. + * All rights reserved. This program and the accompanying materials + * are made available under the terms of the Eclipse Public License v1.0 + * which accompanies this distribution, and is available at + * http://www.eclipse.org/legal/epl-v10.html + * + * Contributors: + * Frank Becker - initial API and implementation + *******************************************************************************/ + +package org.eclipse.mylyn.commons.core; + +import java.io.IOException; +import java.io.StringReader; +import java.text.ParseException; + +import junit.framework.TestCase; + +public class HtmlStreamTokenizerTest extends TestCase { + + public void testDivSelfTerminatingNoSpace() throws IOException, ParseException { + HtmlStreamTokenizer htmlStreamTokenizer = new HtmlStreamTokenizer(new StringReader("<div/>"), null); + HtmlStreamTokenizer.Token token = htmlStreamTokenizer.nextToken(); + assertEquals("div", ((HtmlTag) token.getValue()).getTagName()); + assertTrue(((HtmlTag) token.getValue()).isSelfTerminating()); + } + + public void testDivSelfTerminatingLeadingSpace() throws IOException, ParseException { + HtmlStreamTokenizer htmlStreamTokenizer = new HtmlStreamTokenizer(new StringReader("<div />"), null); + HtmlStreamTokenizer.Token token = htmlStreamTokenizer.nextToken(); + assertEquals("div", ((HtmlTag) token.getValue()).getTagName()); + assertTrue(((HtmlTag) token.getValue()).isSelfTerminating()); + } + + public void testDivSelfTerminatingLeadingSpacePendingSpace() throws IOException, ParseException { + HtmlStreamTokenizer htmlStreamTokenizer = new HtmlStreamTokenizer(new StringReader("<div / >"), null); + HtmlStreamTokenizer.Token token = htmlStreamTokenizer.nextToken(); + assertEquals("div", ((HtmlTag) token.getValue()).getTagName()); + assertTrue(((HtmlTag) token.getValue()).isSelfTerminating()); + } + + public void testDivSelfTerminatingPendingSpace() throws IOException, ParseException { + HtmlStreamTokenizer htmlStreamTokenizer = new HtmlStreamTokenizer(new StringReader("<div/ >"), null); + HtmlStreamTokenizer.Token token = htmlStreamTokenizer.nextToken(); + assertEquals("div", ((HtmlTag) token.getValue()).getTagName()); + assertTrue(((HtmlTag) token.getValue()).isSelfTerminating()); + } + + public void testImgSelfTerminatingNoSpace() throws IOException, ParseException { + HtmlStreamTokenizer htmlStreamTokenizer = new HtmlStreamTokenizer(new StringReader("<img src=\"test.png\"/>"), + null); + HtmlStreamTokenizer.Token token = htmlStreamTokenizer.nextToken(); + assertEquals("img", ((HtmlTag) token.getValue()).getTagName()); + assertTrue(((HtmlTag) token.getValue()).isSelfTerminating()); + } + + public void testImgSelfTerminatingLeadingSpace() throws IOException, ParseException { + HtmlStreamTokenizer htmlStreamTokenizer = new HtmlStreamTokenizer(new StringReader("<img src=\"test.png\" />"), + null); + HtmlStreamTokenizer.Token token = htmlStreamTokenizer.nextToken(); + assertEquals("img", ((HtmlTag) token.getValue()).getTagName()); + assertTrue(((HtmlTag) token.getValue()).isSelfTerminating()); + } + + public void testImgSelfTerminatingLeadingSpacePendingSpace() throws IOException, ParseException { + HtmlStreamTokenizer htmlStreamTokenizer = new HtmlStreamTokenizer( + new StringReader("<img src=\"test.png\" / >"), null); + HtmlStreamTokenizer.Token token = htmlStreamTokenizer.nextToken(); + assertEquals("img", ((HtmlTag) token.getValue()).getTagName()); + assertTrue(((HtmlTag) token.getValue()).isSelfTerminating()); + } + + public void testImgSelfTerminatingPendingSpace() throws IOException, ParseException { + HtmlStreamTokenizer htmlStreamTokenizer = new HtmlStreamTokenizer(new StringReader("<img src=\"test.png\"/ >"), + null); + HtmlStreamTokenizer.Token token = htmlStreamTokenizer.nextToken(); + assertEquals("img", ((HtmlTag) token.getValue()).getTagName()); + assertTrue(((HtmlTag) token.getValue()).isSelfTerminating()); + } +} diff --git a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/AllCommonsTests.java b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/AllCommonsTests.java index 7654ea99..a215da52 100644 --- a/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/AllCommonsTests.java +++ b/org.eclipse.mylyn.commons.tests/src/org/eclipse/mylyn/commons/tests/AllCommonsTests.java @@ -14,6 +14,7 @@ package org.eclipse.mylyn.commons.tests; import junit.framework.Test; import junit.framework.TestSuite; +import org.eclipse.mylyn.commons.core.HtmlStreamTokenizerTest; import org.eclipse.mylyn.commons.tests.core.AuthenticatedProxyTest; import org.eclipse.mylyn.commons.tests.core.CommonListenerListTest; import org.eclipse.mylyn.commons.tests.core.CoreUtilTest; @@ -48,6 +49,7 @@ public class AllCommonsTests { suite.addTestSuite(CommonStoreTest.class); suite.addTestSuite(Html2TextReaderTest.class); suite.addTestSuite(CommonHttpMethod3Test.class); + suite.addTestSuite(HtmlStreamTokenizerTest.class); return suite; } |