From 5ea116fa52481f2cbbae0b6611ccac7eb8f59e54 Mon Sep 17 00:00:00 2001 From: rmohan Date: Fri, 18 Sep 2020 13:45:43 -0700 Subject: [PATCH 1/3] First draft of change to allow dotted attributes in Visualforce --- pmd-visualforce/etc/grammar/VfParser.jjt | 3 ++- .../java/net/sourceforge/pmd/lang/vf/ast/VfParserTest.java | 5 +++++ 2 files changed, 7 insertions(+), 1 deletion(-) diff --git a/pmd-visualforce/etc/grammar/VfParser.jjt b/pmd-visualforce/etc/grammar/VfParser.jjt index 5e1bbf20d1..149308252a 100644 --- a/pmd-visualforce/etc/grammar/VfParser.jjt +++ b/pmd-visualforce/etc/grammar/VfParser.jjt @@ -67,6 +67,7 @@ PARSER_END(VfParser) | <#ALPHANUM_CHAR: ( | ) > | <#IDENTIFIER_CHAR: ( | [ "_", "-", ":" ] ) > | <#IDENTIFIER: ()* > +| <#IDENTIFIER_DOTTED: ( )* > | <#XMLNAME: ( | "_" | ":") ()* > | <#QUOTED_STRING_NO_BREAKS: ( "'" ( ~["'", "\r", "\n"] )* "'" ) | ( "\"" ( ~["\"", "\r", "\n"] )* "\"" ) > @@ -216,7 +217,7 @@ PARSER_END(VfParser) TOKEN : { - > + > | " > : AfterTagState | " | "!>") > : AfterTagState | " | "/ >") > : AfterTagState diff --git a/pmd-visualforce/src/test/java/net/sourceforge/pmd/lang/vf/ast/VfParserTest.java b/pmd-visualforce/src/test/java/net/sourceforge/pmd/lang/vf/ast/VfParserTest.java index f425470314..d14396e4a7 100644 --- a/pmd-visualforce/src/test/java/net/sourceforge/pmd/lang/vf/ast/VfParserTest.java +++ b/pmd-visualforce/src/test/java/net/sourceforge/pmd/lang/vf/ast/VfParserTest.java @@ -26,4 +26,9 @@ public class VfParserTest extends AbstractVfNodesTest { vf.parse("${\"yes\"}"); } + @Test + public void testAttributeNameWithDot() { + vf.parse(""); + } + } From 7e7182b26df56a93b2c40178e79bfe86a190eae7 Mon Sep 17 00:00:00 2001 From: rmohan Date: Tue, 22 Sep 2020 10:29:47 -0700 Subject: [PATCH 2/3] Modifying VF tokenizer test content to keep up with the minor grammar change Streamlined IDENTIFIED_DOTTED logic. Added a couple more negative tests --- pmd-visualforce/etc/grammar/VfParser.jjt | 4 +- .../pmd/lang/vf/ast/VfParserTest.java | 32 ++++++++ .../cpd/testdata/SampleUnescapeElWithTab.txt | 74 +++++++++---------- 3 files changed, 71 insertions(+), 39 deletions(-) diff --git a/pmd-visualforce/etc/grammar/VfParser.jjt b/pmd-visualforce/etc/grammar/VfParser.jjt index 149308252a..a97ba3629f 100644 --- a/pmd-visualforce/etc/grammar/VfParser.jjt +++ b/pmd-visualforce/etc/grammar/VfParser.jjt @@ -67,7 +67,7 @@ PARSER_END(VfParser) | <#ALPHANUM_CHAR: ( | ) > | <#IDENTIFIER_CHAR: ( | [ "_", "-", ":" ] ) > | <#IDENTIFIER: ()* > -| <#IDENTIFIER_DOTTED: ( )* > +| <#IDENTIFIER_DOTTED: ( )+ > | <#XMLNAME: ( | "_" | ":") ()* > | <#QUOTED_STRING_NO_BREAKS: ( "'" ( ~["'", "\r", "\n"] )* "'" ) | ( "\"" ( ~["\"", "\r", "\n"] )* "\"" ) > @@ -217,7 +217,7 @@ PARSER_END(VfParser) TOKEN : { - > + | > | " > : AfterTagState | " | "!>") > : AfterTagState | " | "/ >") > : AfterTagState diff --git a/pmd-visualforce/src/test/java/net/sourceforge/pmd/lang/vf/ast/VfParserTest.java b/pmd-visualforce/src/test/java/net/sourceforge/pmd/lang/vf/ast/VfParserTest.java index d14396e4a7..6ce22de09c 100644 --- a/pmd-visualforce/src/test/java/net/sourceforge/pmd/lang/vf/ast/VfParserTest.java +++ b/pmd-visualforce/src/test/java/net/sourceforge/pmd/lang/vf/ast/VfParserTest.java @@ -6,6 +6,8 @@ package net.sourceforge.pmd.lang.vf.ast; import org.junit.Test; +import net.sourceforge.pmd.lang.ast.ParseException; + /** * @author sergey.gorbaty */ @@ -31,4 +33,34 @@ public class VfParserTest extends AbstractVfNodesTest { vf.parse(""); } + @Test + public void testAttributeNameWithUnderscore() { + vf.parse(""); + } + + @Test + public void testAttributeNameWithColon() { + vf.parse(""); + } + + @Test(expected = ParseException.class) + public void testAttributeNameWithInvalidSymbol() { + vf.parse(""); + } + + @Test(expected = ParseException.class) + public void testAttributeNameWithInvalidDot() { + vf.parse(""); + } + + @Test(expected = ParseException.class) + public void testAttributeNameWithInvalidDotV2() { + vf.parse(""); + } + + @Test(expected = ParseException.class) + public void testAttributeNameWithInvalidDotV3() { + vf.parse(""); + } + } diff --git a/pmd-visualforce/src/test/resources/net/sourceforge/pmd/lang/vf/cpd/testdata/SampleUnescapeElWithTab.txt b/pmd-visualforce/src/test/resources/net/sourceforge/pmd/lang/vf/cpd/testdata/SampleUnescapeElWithTab.txt index 6453afcb92..3b279e6b92 100644 --- a/pmd-visualforce/src/test/resources/net/sourceforge/pmd/lang/vf/cpd/testdata/SampleUnescapeElWithTab.txt +++ b/pmd-visualforce/src/test/resources/net/sourceforge/pmd/lang/vf/cpd/testdata/SampleUnescapeElWithTab.txt @@ -1,42 +1,42 @@ [Image] or [Truncated image[ Bcol Ecol L1 - [24] 1 1 - [85] 2 10 - [88] 11 11 + [25] 1 1 + [86] 2 10 + [89] 11 11 L2 - [24] 2 2 - [85] 3 6 - [87] 8 10 - [91] 11 11 - [94] 12 12 - [105] 13 22 - [103] 23 23 - [87] 25 28 - [91] 29 29 - [94] 30 30 - [105] 31 38 - [103] 39 39 - [87] 41 44 - [91] 45 45 - [94] 46 46 - [104] 47 48 - [66] 49 57 - [41] 58 58 - [66] 59 67 - [73] 68 68 - [105] 69 69 - [104] 70 71 - [66] 72 81 - [73] 82 82 - [103] 83 83 - [87] 85 86 - [91] 87 87 - [94] 88 88 - [105] 89 99 - [103] 100 100 - [90] 101 102 + [25] 2 2 + [86] 3 6 + [88] 8 10 + [92] 11 11 + [95] 12 12 + [106] 13 22 + [104] 23 23 + [88] 25 28 + [92] 29 29 + [95] 30 30 + [106] 31 38 + [104] 39 39 + [88] 41 44 + [92] 45 45 + [95] 46 46 + [105] 47 48 + [67] 49 57 + [42] 58 58 + [67] 59 67 + [74] 68 68 + [106] 69 69 + [105] 70 71 + [67] 72 81 + [74] 82 82 + [104] 83 83 + [88] 85 86 + [92] 87 87 + [95] 88 88 + [106] 89 99 + [104] 100 100 + [91] 101 102 L3 - [25] 1 2 - [85] 3 11 - [88] 12 12 + [26] 1 2 + [86] 3 11 + [89] 12 12 EOF From 90e7d0911010cac54c0b7c692186b983433b90b5 Mon Sep 17 00:00:00 2001 From: Andreas Dangel Date: Thu, 22 Oct 2020 09:47:55 +0200 Subject: [PATCH 3/3] [doc] Update release notes, refs #2834, fixes #2765 --- docs/pages/release_notes.md | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/docs/pages/release_notes.md b/docs/pages/release_notes.md index b8f8783555..f2fc0c4ab4 100644 --- a/docs/pages/release_notes.md +++ b/docs/pages/release_notes.md @@ -16,9 +16,14 @@ This is a {{ site.pmd.release_type }} release. ### Fixed Issues +* vf (Salesforce VisualForce) + * [#2765](https://github.com/pmd/pmd/issues/2765): \[vf] Attributes with dot cause a VfParseException + ### API Changes ### External Contributions +* [#2834](https://github.com/pmd/pmd/pull/2834): \[vf] Allow attributes with dot in Visualforce - [rmohan20](https://github.com/rmohan20) + {% endtocmaker %}