New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[jsp] JspTokenManager has a problem about jsp scriptlet #1402

Closed
duanyanan opened this Issue Oct 21, 2018 · 4 comments

Comments

Projects
None yet
3 participants
@duanyanan

duanyanan commented Oct 21, 2018

Affects PMD Version: 6.7.0

Rule: None

Description: I use pmd-jsp.jar to tokenize the jsp source file, and I want to extract jspscriptlet from the file, but the bound about "%>" has some problems.

Code Sample demonstrating the issue:

//just get the token list
String filepath = "C:\\test.jsp";
File f = new File(filepath);
InputStreamReader isr = new InputStreamReader(new FileInputStream(f));
JspTokenManager jspTokenManager = new JspTokenManager(isr);
List<Token> tokenList = new ArrayList<Token>();
Token token = (Token)jspTokenManager.getNextToken();
tokenList.add(token);
while (!token.image.isEmpty()){
    token = (Token)jspTokenManager.getNextToken();
    tokenList.add(token);
}

Following is a part of source code:

<%
String nodeContent = "<% %>";
%>
<%
<![cdata[
String nodeContent = "<% %>";
]]>
%>

And the token list is below:

"<%", "\nString nodeContent = \"<%lalal" ,"%>", "lalala\";%>\n"
"<%", "\n<![cdata[\nString nodeContent = \"<%", "%>", "\";\n]]>\n%>"

So the bound about "%>" has some problems.

Running PMD through: pmd-jsp-6.7.0.jar & pmd-core-6.7.0.jar

@adangel adangel changed the title from JspTokenManager has a problem about jsp scriptlet to [jsp] JspTokenManager has a problem about jsp scriptlet Oct 22, 2018

@adangel adangel added the a:bug label Oct 22, 2018

@adangel

This comment has been minimized.

Member

adangel commented Oct 22, 2018

Thanks for reporting this. It's definitely a bug in the parser/grammar.
I had a short look into the grammar, and it seems, that we would need an additional state for entering the string... currently, we consider anything except "%>" as part of the scriptlet but any "%>" is interpreted as the end of the scriptlet (regardless, whether it is in quotes or not).

JustPRV added a commit to JustPRV/pmd that referenced this issue Oct 23, 2018

@jsotuyod jsotuyod added the has:pr label Oct 23, 2018

@adangel adangel added this to the 6.9.0 milestone Oct 25, 2018

adangel added a commit that referenced this issue Oct 25, 2018

@duanyanan

This comment has been minimized.

duanyanan commented Oct 30, 2018

Though the problem with string "<% %>" has been solved, the tag "jsp:scriptlet </jsp:scriptlet> “ still can't correctly deal the string. Because of this, JspParser also has the same problem. Please check :)

@adangel

This comment has been minimized.

Member

adangel commented Oct 30, 2018

Can you please open a new issue for this? Thanks!

@duanyanan

This comment has been minimized.

duanyanan commented Oct 30, 2018

#1421 Here is the new issue. : )

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment