[155895] [validation] JSP validation does not detect double quotes in page-tag
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/HTMLCoreMessages.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/HTMLCoreMessages.java index f2f93b1..e3736d8 100644 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/HTMLCoreMessages.java +++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/HTMLCoreMessages.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2010 IBM Corporation and others. + * Copyright (c) 2005, 2011 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 @@ -53,6 +53,7 @@ public static String _ERROR_Resource_not_found_0; public static String Obsolete_attribute_name___ERROR_; public static String Obsolete_tag___ERROR_; + public static String Invalid_text_in_tag__ERROR_; static { // load message values from bundle file
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/HTMLCorePluginResources.properties b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/HTMLCorePluginResources.properties index 330193c..ab0f203 100644 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/HTMLCorePluginResources.properties +++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/HTMLCorePluginResources.properties
@@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2004, 2010 IBM Corporation and others. +# Copyright (c) 2004, 2011 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 @@ -34,6 +34,7 @@ DOCTYPE_declaration_not_cl_ERROR_=DOCTYPE declaration not closed. Processing_instruction_not_ERROR_=Processing instruction not closed. CDATA_section_not_closed__ERROR_=CDATA section not closed. +Invalid_text_in_tag__ERROR_=Invalid location of text ({0}) in tag (<{1}>). # From here, the new messages are added for V5 _ERROR_Tag___0___should_be_an_empty_element_tag_1=Tag ({0}) should be an empty-element tag. _ERROR_Attribute_value___0___not_closed__1=Attribute value ({0}) not closed.
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/preferences/HTMLCorePreferenceInitializer.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/preferences/HTMLCorePreferenceInitializer.java index 3130e16..03b3511 100644 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/preferences/HTMLCorePreferenceInitializer.java +++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/preferences/HTMLCorePreferenceInitializer.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2010 IBM Corporation and others. + * Copyright (c) 2005, 2011 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 @@ -101,6 +101,7 @@ node.putInt(HTMLCorePreferenceNames.ELEM_UNCLOSED_END_TAG, ValidationMessage.ERROR); node.putInt(HTMLCorePreferenceNames.ELEM_INVALID_EMPTY_TAG, ValidationMessage.WARNING); node.putInt(HTMLCorePreferenceNames.ELEM_OBSOLETE_NAME, ValidationMessage.WARNING); + node.putInt(HTMLCorePreferenceNames.ELEM_INVALID_TEXT, ValidationMessage.WARNING); // DOCTYPE
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/preferences/HTMLCorePreferenceNames.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/preferences/HTMLCorePreferenceNames.java index af1e90f..c1178f3 100644 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/preferences/HTMLCorePreferenceNames.java +++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/preferences/HTMLCorePreferenceNames.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2005, 2010 IBM Corporation and others. + * Copyright (c) 2005, 2011 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 @@ -267,7 +267,8 @@ public static final String ELEM_UNCLOSED_END_TAG = "elemUnclosedEndTag";//$NON-NLS-1$ public static final String ELEM_INVALID_EMPTY_TAG = "elemInvalidEmptyTag";//$NON-NLS-1$ public static final String ELEM_OBSOLETE_NAME = "elemObsoleteName";//$NON-NLS-1$ - + public static final String ELEM_INVALID_TEXT = "elemInvalidText";//$NON-NLS-1$ + public static final String DOC_DUPLICATE = "docDuplicateTag";//$NON-NLS-1$ public static final String DOC_INVALID_CONTENT = "docInvalidContent";//$NON-NLS-1$ public static final String DOC_DOCTYPE_UNCLOSED = "docDoctypeUnclosed";//$NON-NLS-1$
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/AbstractErrorInfo.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/AbstractErrorInfo.java index 3e9d85d..4135482 100644 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/AbstractErrorInfo.java +++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/AbstractErrorInfo.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2011 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 @@ -24,8 +24,6 @@ this.seg = seg; } - abstract public String getHint(); - abstract public short getTargetType(); public int getLength() { @@ -39,4 +37,13 @@ public int getState() { return this.state; } + + /** + * @return the arguments to be injected into a message for the user about this error + */ + public String[] getMessageArguments() { + String hint = getHint(); + return hint != null ? new String[] { hint } : null; + } + }
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/ErrorInfoImpl.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/ErrorInfoImpl.java index 4710a1e..f134ee4 100644 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/ErrorInfoImpl.java +++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/ErrorInfoImpl.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2005 IBM Corporation and others. + * Copyright (c) 2004, 2011 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 @@ -19,13 +19,46 @@ final class ErrorInfoImpl extends AbstractErrorInfo { private Node target = null; - - // private Segment seg = null; /** + * The message arguments to list before the target information + */ + private String[] fPreTargetMsgArgs; + + /** + * The message arguments to list after the target information + */ + private String[] fPostTargetMsgArgs; + + /** + * <p>Create error info without any extra message arguments + * before or after the <code>target</code> information</p> + * + * @param state the error state + * @param errorSeg the <code>Segment</code> to report the error on + * @param target the <code>Node</code> that is causing the error */ public ErrorInfoImpl(int state, Segment errorSeg, Node target) { super(state, errorSeg); this.target = target; + this.fPreTargetMsgArgs = new String[0]; + this.fPostTargetMsgArgs = new String[0]; + } + + /** + * <p>Create error info with extra message arguments before and/or + * after the <code>target</code> information</p> + * + * @param state the error state + * @param errorSeg the <code>Segment</code> to report the error on + * @param target the <code>Node</code> that is causing the error + * @param preTargetMsgArgs message arguments to place before the <code>target</code> information + * @param postTargetMsgInjections message arguments to place after the <code>target</code> information + */ + public ErrorInfoImpl(int state, Segment errorSeg, Node target, String[] preTargetMsgArgs, String[] postTargetMsgInjections) { + super(state, errorSeg); + this.target = target; + this.fPreTargetMsgArgs = preTargetMsgArgs; + this.fPostTargetMsgArgs = postTargetMsgInjections; } /** @@ -51,6 +84,44 @@ } } + /* (non-Javadoc) + * @see org.eclipse.wst.html.core.internal.validate.AbstractErrorInfo#getMessageArguments() + */ + public String[] getMessageArguments() { + String[] messageInjections = new String[this.fPreTargetMsgArgs.length + 1 + this.fPostTargetMsgArgs.length]; + //copy the pre target message injections in + System.arraycopy(this.fPreTargetMsgArgs, 0, messageInjections, 0, this.fPreTargetMsgArgs.length); + int nextIndex = fPreTargetMsgArgs.length; + + //put the target message injection in + switch (target.getNodeType()) { + case Node.ATTRIBUTE_NODE : + switch (getState()) { + case UNDEFINED_VALUE_ERROR : + case MISMATCHED_VALUE_ERROR : + case UNCLOSED_ATTR_VALUE : + case RESOURCE_NOT_FOUND : + //D210422 + messageInjections[nextIndex] = ((Attr) target).getValue(); + break; + default : + messageInjections[nextIndex] = target.getNodeName(); + break; + } + break; + case Node.TEXT_NODE : + messageInjections[nextIndex] = ((Text) target).getData(); + break; + case Node.ELEMENT_NODE : + default : + messageInjections[nextIndex] = target.getNodeName(); + break; + } + //copy the post target message injections in + System.arraycopy(this.fPostTargetMsgArgs, 0, messageInjections, nextIndex+1, this.fPostTargetMsgArgs.length); + return messageInjections; + } + public short getTargetType() { return target.getNodeType(); }
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/ErrorState.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/ErrorState.java index f64d50e..5ebf14c 100644 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/ErrorState.java +++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/ErrorState.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2010 IBM Corporation and others. + * Copyright (c) 2004, 2011 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 @@ -37,6 +37,8 @@ static final int INVALID_EMPTY_ELEMENT_TAG = 112; static final int UNCLOSED_ATTR_VALUE = 113; //D210422 static final int RESOURCE_NOT_FOUND = 114; //D210422 + static final int INVALID_TEXT_IN_ELEM_ERROR = 115; + // layout error static final int LAYOUT_ERROR_LEVEL = 1000; static final int INVALID_CONTENT_ERROR = 1001;
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/MessageFactory.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/MessageFactory.java index d7ed235..1614671 100644 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/MessageFactory.java +++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/MessageFactory.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2010 IBM Corporation and others. + * Copyright (c) 2004, 2011 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 @@ -115,6 +115,7 @@ mapToKey(HTMLCorePreferenceNames.ELEM_INVALID_EMPTY_TAG, elemTable, INVALID_EMPTY_ELEMENT_TAG, MSG_INVALID_EMPTY_ELEMENT_TAG); mapToKey(HTMLCorePreferenceNames.ELEM_OBSOLETE_NAME, elemTable, OBSOLETE_TAG_NAME_ERROR, MSG_OBSOLETE_TAG_ERROR); + mapToKey(HTMLCorePreferenceNames.ELEM_INVALID_TEXT, elemTable, INVALID_TEXT_IN_ELEM_ERROR, MSG_INVALID_TEXT_IN_ELEM_ERROR); // document type error map ErrorTable docTable = errTables[NodeType.DOCUMENT_TYPE];// short hand @@ -242,7 +243,8 @@ private static final String MSG_RESOURCE_NOT_FOUND = HTMLCoreMessages._ERROR_Resource_not_found_0; private static final String MSG_OBSOLETE_ATTR_ERROR = HTMLCoreMessages.Obsolete_attribute_name___ERROR_; private static final String MSG_OBSOLETE_TAG_ERROR = HTMLCoreMessages.Obsolete_tag___ERROR_; - + private static final String MSG_INVALID_TEXT_IN_ELEM_ERROR = HTMLCoreMessages.Invalid_text_in_tag__ERROR_; + private ErrorTable[] errTables = new ErrorTable[NodeType.MAX_TYPE]; // static { @@ -335,7 +337,7 @@ return MSG_UNKNOWN_ERROR; String template = tab.getMessage(info.getState()); - Object[] arguments = {info.getHint()}; + Object[] arguments = (info instanceof AbstractErrorInfo) ? ((AbstractErrorInfo) info).getMessageArguments() : new Object[] {info.getHint()}; String s = null; try { s = NLS.bind(template, arguments);
diff --git a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/SyntaxValidator.java b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/SyntaxValidator.java index 4dd8979..9265639 100644 --- a/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/SyntaxValidator.java +++ b/bundles/org.eclipse.wst.html.core/src/org/eclipse/wst/html/core/internal/validate/SyntaxValidator.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2004, 2010 IBM Corporation and others. + * Copyright (c) 2004, 2011 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 @@ -108,6 +108,9 @@ validateTagCase(info); } } + + //validate the syntax of the attributes + validateAttributes(info); } private void getInfo(ElementInfo info) { @@ -406,8 +409,37 @@ return -1; } + /** + * <p>Used to validate the syntax of the arguments in a tag.</p> + * + * @param info the <code>ElementInfo</code> about the tag to validate + */ + private void validateAttributes(ElementInfo info) { + if(info != null && info.hasStartTag()) { + ITextRegionList list = info.startTag.getRegions(); + + //for each region in the tag, these make up the arguments + for(int i = 0; i < list.size(); ++i) { + ITextRegion region = list.get(i); + String type = region.getType(); + + //if the type is undefined then there is a syntax error + if(type == DOMRegionContext.UNDEFINED) { + String invalidText = info.startTag.getFullText(region).trim(); + Segment errorSeg = new Segment(info.startTag.getStartOffset() + region.getStart(), invalidText.length()); + report(INVALID_TEXT_IN_ELEM_ERROR, errorSeg, info.target, new String[]{invalidText}, new String[0]); + } + } + } + } + private void report(int state, Segment errorSeg, Node node) { ErrorInfo info = new ErrorInfoImpl(state, errorSeg, node); reporter.report(info); } + + private void report(int state, Segment errorSeg, Node node, String[] preTargetMsgInjections, String[] postTargetMsgInjections) { + ErrorInfo info = new ErrorInfoImpl(state, errorSeg, node, preTargetMsgInjections, postTargetMsgInjections); + reporter.report(info); + } }
diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/HTMLUIMessages.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/HTMLUIMessages.java index 1c2c15b..5355458 100644 --- a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/HTMLUIMessages.java +++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/HTMLUIMessages.java
@@ -1,5 +1,5 @@ /********************************************************************** - * Copyright (c) 2005, 2010 IBM Corporation and others. All rights reserved. This + * Copyright (c) 2005, 2011 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 @@ -200,6 +200,7 @@ public static String HTMLValidationPreferencePage_7; public static String HTMLValidationPreferencePage_8; public static String HTMLValidationPreferencePage_9; + public static String HTMLValidationPreferencePage_36; // Validation public static String Validation_Title;
diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/HTMLUIPluginResources.properties b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/HTMLUIPluginResources.properties index 3604722..7fe67e1 100644 --- a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/HTMLUIPluginResources.properties +++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/HTMLUIPluginResources.properties
@@ -1,5 +1,5 @@ ############################################################################### -# Copyright (c) 2004, 2009 IBM Corporation and others. +# Copyright (c) 2004, 2011 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 @@ -175,6 +175,7 @@ HTMLValidationPreferencePage_8=Unknown tag name: HTMLValidationPreferencePage_9=Invalid tag name: HTMLValidationPreferencePage_35=Attribute value refers to missing resource: +HTMLValidationPreferencePage_36=Invalid location of text in tag: Validation_Title=Validation Settings Changed Validation_Workspace=The validation settings have changed. A full validation is required for changes to take effect. Validate now?
diff --git a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/preferences/ui/HTMLValidationPreferencePage.java b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/preferences/ui/HTMLValidationPreferencePage.java index 1a1f612..966bffc 100644 --- a/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/preferences/ui/HTMLValidationPreferencePage.java +++ b/bundles/org.eclipse.wst.html.ui/src/org/eclipse/wst/html/ui/internal/preferences/ui/HTMLValidationPreferencePage.java
@@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2008 IBM Corporation and others. + * Copyright (c) 2008, 2011 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 @@ -131,6 +131,10 @@ label = HTMLUIMessages.HTMLValidationPreferencePage_21; addComboBox(inner, label, HTMLCorePreferenceNames.ELEM_INVALID_EMPTY_TAG, SEVERITIES, errorWarningIgnoreLabel, 0); + + label = HTMLUIMessages.HTMLValidationPreferencePage_36; + addComboBox(inner, label, HTMLCorePreferenceNames.ELEM_INVALID_TEXT, SEVERITIES, errorWarningIgnoreLabel, 0); + // End Element Section // The Attribute validation section