[159926] (1.5.3) HTMLAttributeValidator has reversed JSP-aware attribute name and value checks?
diff --git a/tests/org.eclipse.jst.jsp.ui.tests/META-INF/MANIFEST.MF b/tests/org.eclipse.jst.jsp.ui.tests/META-INF/MANIFEST.MF index 4b68613..2f89228 100644 --- a/tests/org.eclipse.jst.jsp.ui.tests/META-INF/MANIFEST.MF +++ b/tests/org.eclipse.jst.jsp.ui.tests/META-INF/MANIFEST.MF
@@ -23,6 +23,7 @@ org.eclipse.jst.jsp.ui.tests.search, org.eclipse.jst.jsp.ui.tests.threaded, org.eclipse.jst.jsp.ui.tests.util, + org.eclipse.jst.jsp.ui.tests.validation, org.eclipse.jst.jsp.ui.tests.viewer Require-Bundle: org.eclipse.jface.text, org.eclipse.ui, @@ -42,5 +43,7 @@ org.eclipse.ui.views, org.eclipse.core.runtime, org.eclipse.wst.xml.ui, - com.ibm.icu + com.ibm.icu, + org.eclipse.wst.html.ui, + org.eclipse.wst.validation Eclipse-LazyStart: true
diff --git a/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/JSPUITestSuite.java b/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/JSPUITestSuite.java index 5b41a17..978ece5 100644 --- a/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/JSPUITestSuite.java +++ b/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/JSPUITestSuite.java
@@ -25,6 +25,7 @@ import org.eclipse.jst.jsp.ui.tests.pagedirective.TestPageDirective; import org.eclipse.jst.jsp.ui.tests.partitioning.TestStructuredPartitionerJSP; import org.eclipse.jst.jsp.ui.tests.registry.AdapterFactoryRegistryTest; +import org.eclipse.jst.jsp.ui.tests.validation.JSPHTMLValidatorTest; import org.eclipse.jst.jsp.ui.tests.viewer.TestViewerConfigurationJSP; @@ -60,6 +61,7 @@ addTest(new TestSuite(TestModelEmbeddedContentType.class, "TestModelEmbeddedContentType")); addTest(new TestSuite(TestContentDescription.class, "Content Description Tests")); + addTest(new TestSuite(JSPHTMLValidatorTest.class, "JSPHTMLValidatorTest")); // pa_TODO fix this test //addTest(new TestSuite(JSPSearchTests.class)); }
diff --git a/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/util/ProjectUtil.java b/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/util/ProjectUtil.java index 4b2b307..338b54a 100644 --- a/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/util/ProjectUtil.java +++ b/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/util/ProjectUtil.java
@@ -7,14 +7,18 @@ import java.net.URL; import java.util.ArrayList; import java.util.Arrays; +import java.util.Enumeration; import java.util.List; import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; import org.eclipse.core.resources.IProject; import org.eclipse.core.resources.IProjectDescription; +import org.eclipse.core.resources.IWorkspaceRunnable; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; import org.eclipse.core.runtime.IPath; +import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.core.runtime.Path; import org.eclipse.jdt.core.IClasspathEntry; @@ -61,15 +65,26 @@ } } - /** - * - * @param entryname path relative to TEST plugin starting w/ a "/" - * (eg. "/testfiles/bugnumber/struts-logic.tld") - * @param fullPath path relative to junit test workpace - * (eg. "/myruntimeproj/struts-logic.tld") - * @return - */ - public static IFile copyBundleEntryIntoWorkspace(String entryname, String fullPath) { + static void _copyBundleEntriesIntoWorkspace(final String rootEntry, final String fullTargetPath) throws CoreException { + Enumeration entries = JSPUITestsPlugin.getDefault().getBundle().getEntryPaths(rootEntry); + while (entries != null && entries.hasMoreElements()) { + String entryPath = entries.nextElement().toString(); + String targetPath = new Path(fullTargetPath + "/" + entryPath.substring(rootEntry.length())).toString(); + if (entryPath.endsWith("/")) { + IFolder folder = ResourcesPlugin.getWorkspace().getRoot().getFolder(new Path(targetPath)); + if (!folder.exists()) { + folder.create(true, true, new NullProgressMonitor()); + } + _copyBundleEntriesIntoWorkspace(entryPath, targetPath); + } + else { + _copyBundleEntryIntoWorkspace(entryPath, targetPath); + } + // System.out.println(entryPath + " -> " + targetPath); + } + } + + static IFile _copyBundleEntryIntoWorkspace(String entryname, String fullPath) throws CoreException { IFile file = null; URL entry = JSPUITestsPlugin.getDefault().getBundle().getEntry(entryname); if (entry != null) { @@ -83,7 +98,12 @@ } file = ResourcesPlugin.getWorkspace().getRoot().getFile(new Path(fullPath)); if (file != null) { - file.create(new ByteArrayInputStream(output.toByteArray()), true, new NullProgressMonitor()); + if (!file.exists()) { + file.create(new ByteArrayInputStream(output.toByteArray()), true, new NullProgressMonitor()); + } + else { + file.setContents(new ByteArrayInputStream(output.toByteArray()), true, false, new NullProgressMonitor()); + } } } catch (IOException e) { @@ -95,6 +115,46 @@ } return file; } + + public static void copyBundleEntriesIntoWorkspace(final String rootEntry, final String fullTargetPath) { + IWorkspaceRunnable runnable = new IWorkspaceRunnable() { + public void run(IProgressMonitor monitor) throws CoreException { + _copyBundleEntriesIntoWorkspace(rootEntry, fullTargetPath); + ResourcesPlugin.getWorkspace().checkpoint(true); + } + }; + try { + ResourcesPlugin.getWorkspace().run(runnable, new NullProgressMonitor()); + } + catch (CoreException e) { + e.printStackTrace(); + } + } + + /** + * + * @param entryname path relative to TEST plugin starting w/ a "/" + * (eg. "/testfiles/bugnumber/struts-logic.tld") + * @param fullPath path relative to junit test workpace + * (eg. "/myruntimeproj/struts-logic.tld") + * @return + */ + public static IFile copyBundleEntryIntoWorkspace(final String entryname, final String fullPath) { + final IFile file[] = new IFile[1]; + IWorkspaceRunnable runnable = new IWorkspaceRunnable() { + public void run(IProgressMonitor monitor) throws CoreException { + file[0] = _copyBundleEntryIntoWorkspace(entryname, fullPath); + ResourcesPlugin.getWorkspace().checkpoint(true); + } + }; + try { + ResourcesPlugin.getWorkspace().run(runnable, new NullProgressMonitor()); + } + catch (CoreException e) { + e.printStackTrace(); + } + return file[0]; + } public static IProject createProject(String name, IPath location, String[] natureIds) { IProjectDescription description = ResourcesPlugin.getWorkspace().newProjectDescription(name);
diff --git a/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/validation/JSPHTMLValidatorTest.java b/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/validation/JSPHTMLValidatorTest.java new file mode 100644 index 0000000..01b331d --- /dev/null +++ b/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/validation/JSPHTMLValidatorTest.java
@@ -0,0 +1,95 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jst.jsp.ui.tests.validation; + +import junit.framework.TestCase; + +import org.eclipse.core.resources.ResourcesPlugin; +import org.eclipse.jdt.core.JavaCore; +import org.eclipse.jst.jsp.ui.tests.util.ProjectUtil; +import org.eclipse.wst.html.internal.validation.HTMLValidator; +import org.eclipse.wst.validation.internal.provisional.core.IReporter; + +/** + * Tests HTML validator on jsp file + */ +public class JSPHTMLValidatorTest extends TestCase { + String wtp_autotest_noninteractive = null; + private static final String PROJECT_NAME = "bug_143209"; + + protected void setUp() throws Exception { + super.setUp(); + String noninteractive = System.getProperty("wtp.autotest.noninteractive"); + if (noninteractive != null) + wtp_autotest_noninteractive = noninteractive; + System.setProperty("wtp.autotest.noninteractive", "true"); + + if (!ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME).exists()) { + ProjectUtil.createProject(PROJECT_NAME, null, new String[]{JavaCore.NATURE_ID}); + ProjectUtil.copyBundleEntriesIntoWorkspace("/testfiles/" + PROJECT_NAME, "/" + PROJECT_NAME); + } + assertTrue("project could not be created", ResourcesPlugin.getWorkspace().getRoot().getProject(PROJECT_NAME).exists()); + } + + protected void tearDown() throws Exception { + super.tearDown(); + if (wtp_autotest_noninteractive != null) + System.setProperty("wtp.autotest.noninteractive", wtp_autotest_noninteractive); + } + + /** + * Tests jsp expression in html attributes in jsp file + * + * @throws Exception + */ + public void testJSPinAttributes() throws Exception { + HTMLValidator validator = new HTMLValidator(); + IReporter reporter = new ReporterForTest(); + ValidationContextForTest helper = new ValidationContextForTest(); + String filePath = "/" + PROJECT_NAME + "/WebContent/usejspinattribute.jsp"; + helper.setURI(filePath); + validator.validate(helper, reporter); + + assertTrue("jsp in attributes are errors when they should not be (in .jsp)", reporter.getMessages().isEmpty()); + } + + /** + * Tests jsp expression in html attributes in html file + * + * @throws Exception + */ + public void testJSPinAttributesHTML() throws Exception { + HTMLValidator validator = new HTMLValidator(); + IReporter reporter = new ReporterForTest(); + ValidationContextForTest helper = new ValidationContextForTest(); + String filePath = "/" + PROJECT_NAME + "/WebContent/usejspinattribute.html"; + helper.setURI(filePath); + validator.validate(helper, reporter); + + assertTrue("jsp in attributes are not errors when they should be (in .html)", !reporter.getMessages().isEmpty()); + } + + /** + * Tests bad attribute names in jsp file false + * + * @throws Exception + */ + public void testBadAttributeName() throws Exception { + HTMLValidator validator = new HTMLValidator(); + IReporter reporter = new ReporterForTest(); + ValidationContextForTest helper = new ValidationContextForTest(); + String filePath = "/" + PROJECT_NAME + "/WebContent/badattributenames.jsp"; + helper.setURI(filePath); + validator.validate(helper, reporter); + + assertTrue("bad attribute name is not error when it should be", !reporter.getMessages().isEmpty()); + } +}
diff --git a/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/validation/ReporterForTest.java b/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/validation/ReporterForTest.java new file mode 100644 index 0000000..fea98ac --- /dev/null +++ b/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/validation/ReporterForTest.java
@@ -0,0 +1,59 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jst.jsp.ui.tests.validation; + +import java.util.ArrayList; +import java.util.List; + +import org.eclipse.wst.validation.internal.core.IMessageAccess; +import org.eclipse.wst.validation.internal.provisional.core.IMessage; +import org.eclipse.wst.validation.internal.provisional.core.IReporter; +import org.eclipse.wst.validation.internal.provisional.core.IValidator; + +class ReporterForTest implements IReporter { + List list = new ArrayList(); + + public ReporterForTest() { + super(); + } + + public void addMessage(IValidator origin, IMessage message) { + list.add(message); + } + + public void displaySubtask(IValidator validator, IMessage message) { + /* do not need to implement */ + } + + public IMessageAccess getMessageAccess() { + return null; + } + + public boolean isCancelled() { + return false; + } + + public void removeAllMessages(IValidator origin, Object object) { // do + /* do not need to implement */ + } + + public void removeAllMessages(IValidator origin) { + /* do not need to implement */ + } + + public void removeMessageSubset(IValidator validator, Object obj, String groupName) {// do + /* do not need to implement */ + } + + public List getMessages() { + return list; + } +}
diff --git a/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/validation/ValidationContextForTest.java b/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/validation/ValidationContextForTest.java new file mode 100644 index 0000000..3f613fa --- /dev/null +++ b/tests/org.eclipse.jst.jsp.ui.tests/src/org/eclipse/jst/jsp/ui/tests/validation/ValidationContextForTest.java
@@ -0,0 +1,36 @@ +/******************************************************************************* + * Copyright (c) 2006 IBM Corporation 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: + * IBM Corporation - initial API and implementation + *******************************************************************************/ +package org.eclipse.jst.jsp.ui.tests.validation; + +import org.eclipse.wst.validation.internal.provisional.core.IValidationContext; + +class ValidationContextForTest implements IValidationContext { + private String fURI = null; + + public void setURI(String uri) { + fURI = uri; + } + + public String[] getURIs() { + if (fURI != null) + return new String[]{fURI}; + return new String[0]; + } + + public Object loadModel(String symbolicName) { + return null; + } + + public Object loadModel(String symbolicName, Object[] parms) { + return null; + } + +}
diff --git a/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/WebContent/META-INF/MANIFEST.MF b/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/WebContent/META-INF/MANIFEST.MF new file mode 100644 index 0000000..254272e --- /dev/null +++ b/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/WebContent/META-INF/MANIFEST.MF
@@ -0,0 +1,3 @@ +Manifest-Version: 1.0 +Class-Path: +
diff --git a/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/WebContent/WEB-INF/classes/.keepme b/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/WebContent/WEB-INF/classes/.keepme new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/WebContent/WEB-INF/classes/.keepme
diff --git a/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/WebContent/WEB-INF/lib/.keepme b/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/WebContent/WEB-INF/lib/.keepme new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/WebContent/WEB-INF/lib/.keepme
diff --git a/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/WebContent/WEB-INF/web.xml b/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/WebContent/WEB-INF/web.xml new file mode 100644 index 0000000..2e1d7c0 --- /dev/null +++ b/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/WebContent/WEB-INF/web.xml
@@ -0,0 +1,12 @@ +<?xml version="1.0" encoding="UTF-8"?> +<web-app id="WebApp_ID" version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> + <display-name>bug_143209</display-name> + <welcome-file-list> + <welcome-file>index.html</welcome-file> + <welcome-file>index.htm</welcome-file> + <welcome-file>index.jsp</welcome-file> + <welcome-file>default.html</welcome-file> + <welcome-file>default.htm</welcome-file> + <welcome-file>default.jsp</welcome-file> + </welcome-file-list> +</web-app>
diff --git a/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/WebContent/badattributenames.jsp b/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/WebContent/badattributenames.jsp new file mode 100644 index 0000000..c515970 --- /dev/null +++ b/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/WebContent/badattributenames.jsp
@@ -0,0 +1,9 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> +<title>Insert title here</title> +</head> +<body fakename=""> +</body> +</html> \ No newline at end of file
diff --git a/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/WebContent/usejspinattribute.html b/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/WebContent/usejspinattribute.html new file mode 100644 index 0000000..95bd566 --- /dev/null +++ b/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/WebContent/usejspinattribute.html
@@ -0,0 +1,14 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> +<title>Insert title here</title> +</head> +<!-- jsp expression in attribute value --> +<body bgcolor="<%="red" %>"> +<!-- jsp expression in attribute name --> +<p <%="align" %>="left" /> +<!-- jsp expression as attribute name & value --> +<a <%="href='http://www.eclipse.org'" %>>Eclipse link</a> +</body> +</html> \ No newline at end of file
diff --git a/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/WebContent/usejspinattribute.jsp b/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/WebContent/usejspinattribute.jsp new file mode 100644 index 0000000..95bd566 --- /dev/null +++ b/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/WebContent/usejspinattribute.jsp
@@ -0,0 +1,14 @@ +<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> +<html> +<head> +<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> +<title>Insert title here</title> +</head> +<!-- jsp expression in attribute value --> +<body bgcolor="<%="red" %>"> +<!-- jsp expression in attribute name --> +<p <%="align" %>="left" /> +<!-- jsp expression as attribute name & value --> +<a <%="href='http://www.eclipse.org'" %>>Eclipse link</a> +</body> +</html> \ No newline at end of file
diff --git a/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/build/classes/.keepme b/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/build/classes/.keepme new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/build/classes/.keepme
diff --git a/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/src/.keepme b/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/src/.keepme new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/tests/org.eclipse.jst.jsp.ui.tests/testfiles/bug_143209/src/.keepme