Skip to content

Conversation

@rfelcman
Copy link
Contributor

Bugfix + unit test for a bug #822 .

Radek Felcman added 2 commits June 25, 2020 11:41
Signed-off-by: Radek Felcman <[email protected]>
Signed-off-by: Radek Felcman <[email protected]>
* @return Query string without line comments.
*/
private String removeLineComments(String queryString) {
StringTokenizer multiLineTokenizer = new StringTokenizer(queryString, "\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

will this work for windows line endings (\r\n) as well?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think, that it is tested at NamedNativeQueryJUnitTest.java line 175

Signed-off-by: Radek Felcman <[email protected]>

while (multiLineTokenizer.hasMoreTokens()) {
String s = multiLineTokenizer.nextToken();
if (!"--".equals(s.trim().substring(0,2)))

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

What about comments at the end of the line?

insert into table_name (col1, col2)
  values
     (1,2), -- a comment is also possible here, right?
     (3,4);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Also -- can be part of a string, e.g.

-- valid comment ? (1)
insert into table_name (textCol)
  values -- valid comment ? (2)
     ('test test -- no comment ?
-- no comment ? test test
test test');

Above code would remove comment (1), not detect comment (2) and accidentally remove the second "no comment" line inside a string.

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

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants