diff --git a/pmd/bin/build.xml b/pmd/bin/build.xml
index cfcd22d982..576416ceb7 100644
--- a/pmd/bin/build.xml
+++ b/pmd/bin/build.xml
@@ -392,8 +392,16 @@
+
+
+
+
+
+
+
+
-
+
diff --git a/pmd/etc/changelog.txt b/pmd/etc/changelog.txt
index 5412ed73ab..efbf2bb4f8 100644
--- a/pmd/etc/changelog.txt
+++ b/pmd/etc/changelog.txt
@@ -13,6 +13,8 @@ Fixed bug 2904832 - Type resolution not working for ASTType when using an inner
Correct -benchmark reporting of Rule visits via the RuleChain
Fix issue with Type Resolution incorrectly handling of Classes with same name as a java.lang Class.
+The JSP/JSF parser can now parse Unicode input.
+The JSP/JSP parser can now handle tags. The AST HtmlScript node contains the content.
Dependencies updates: asm updated to 3.2
@@ -23,6 +25,7 @@ New rule:
Controversial : AvoidLiteralsInIfCondition (patch 2591627), UseConcurrentHashMap
StrictExceptions : AvoidCatchingGenericException, AvoidLosingExceptionInformation
Naming : GenericsNaming
+ JSP: NoInlineScript
February 08, 2009 - 4.2.5:
diff --git a/pmd/etc/grammar/JspParser.jjt b/pmd/etc/grammar/JspParser.jjt
index e62defd6d2..9448db9bdf 100644
--- a/pmd/etc/grammar/JspParser.jjt
+++ b/pmd/etc/grammar/JspParser.jjt
@@ -1,13 +1,15 @@
- /* JSP Parser for PMD.
+/* JSP Parser for PMD.
* It supports supports more-or-less well written JSP files.
* The JSP Document style is supported, except for inline DTD.
* The JSP Page style (<% ... %>) is supported.
* Java code is not parsed.
+ * Script code inside is not parsed.
*/
options {
USER_CHAR_STREAM = true;
NODE_USES_PARSER=true;
+ UNICODE_INPUT=true;
IGNORE_CASE = true;
STATIC = false;
@@ -19,7 +21,7 @@ options {
PARSER_BEGIN(JspParser)
/**
* JSP Parser for PMD.
- * @author Pieter – Application Engineers NV/SA – http://www.ae.be
+ * @author Pieter – Application Engineers NV/SA – http://www.ae.be
*/
package net.sourceforge.pmd.jsp.ast;
@@ -78,6 +80,7 @@ PARSER_END(JspParser)
* - JspExpressionState : inside an expression <%= ... %>
* - JspDeclarationState : inside a declaration <%! ... %>
* - JspCommentState : inside a comment <%-- ... --%>
+ * - HtmlScriptContentState : inside an HTML script
*/
@@ -263,6 +266,18 @@ PARSER_END(JspParser)
| < COMMENT_TEXT: (~[]) >
}
+ TOKEN :
+{
+
+ |
+ {
+ // We've done a custom lookahead for the closing and found it.
+ // Put it back into the input stream, so it can be processed normally.
+ input_stream.backup(8);
+ image.setLength(image.length() - 8); // kill the " tag.
+ // This is a context sensitive switch for the token manager, not something one can
+ // express using normal JavaCC syntax. Hence the hoop jumping.
+ if ("script".equalsIgnoreCase(startTagName.image)) {
+ token_source.SwitchTo(HtmlScriptContentState);
+ }
+ }
- (Content())?
+ (HtmlScript() | Content())?
endTagName =
@@ -645,3 +671,16 @@ void DoctypeExternalId() :
{ jjtThis.setUri(quoteContent(systemLiteral.image)); }
)
}
+
+void HtmlScript() :
+{
+ StringBuffer content = new StringBuffer();
+ Token t;
+}
+{
+ (t = { content.append(t.image); })*
+
+ {
+ jjtThis.setImage(content.toString().trim());
+ }
+}
diff --git a/pmd/regress/test/net/sourceforge/pmd/jsp/ast/JspDocStyleTest.java b/pmd/regress/test/net/sourceforge/pmd/jsp/ast/JspDocStyleTest.java
index cf3c5066ae..b38bd95452 100644
--- a/pmd/regress/test/net/sourceforge/pmd/jsp/ast/JspDocStyleTest.java
+++ b/pmd/regress/test/net/sourceforge/pmd/jsp/ast/JspDocStyleTest.java
@@ -1,6 +1,13 @@
package test.net.sourceforge.pmd.jsp.ast;
import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.Comparator;
+import java.util.List;
+import java.util.Set;
+
import net.sourceforge.pmd.jsp.ast.ASTAttribute;
import net.sourceforge.pmd.jsp.ast.ASTAttributeValue;
import net.sourceforge.pmd.jsp.ast.ASTCData;
@@ -8,14 +15,9 @@ import net.sourceforge.pmd.jsp.ast.ASTCommentTag;
import net.sourceforge.pmd.jsp.ast.ASTDoctypeDeclaration;
import net.sourceforge.pmd.jsp.ast.ASTDoctypeExternalId;
import net.sourceforge.pmd.jsp.ast.ASTElement;
+import net.sourceforge.pmd.jsp.ast.ASTHtmlScript;
import org.junit.Test;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
-import java.util.List;
-import java.util.Set;
/**
* Test parsing of a JSP in document style, by checking the generated AST.
*
@@ -156,6 +158,17 @@ public class JspDocStyleTest extends AbstractJspNodesTst {
ASTCommentTag comment = (ASTCommentTag) comments.iterator().next();
assertEquals("Correct comment content expected!", "comment", comment.getImage());
}
+
+ /**
+ * Test parsing of HTML