You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ScriptUtils fails if the sequence '--' occurs within a multi-line comment and on the same line as '*/' #22388
I am using ResourceDatabasePopulator to populate a MySQL database using SQL scripts. These scripts contain multi-line comments of the form:
/*--------------------------------------------
-- This is a multi-line comment block
--------------------------------------------*/
ScriptUtils.executeSqlScript then fails with the error:
Failed to parse SQL script from resource [Byte array resource [resource loaded from byte array]]: Missing block comment end delimiter: */
More Details
What appears to be happening is that ScriptUtils.readScript(LineNumberReader, String, String) trims all single-line comments from the input script before passing it to ScriptUtils.splitSqlScript(). The last line of the comment, containing the block-comment end-delimiter, also gets removed because it assumes that this is a single-line comment. The line does start with the single-line comment prefix '--' after all.
Subsequently the trimmed version of the script is passed to and processed by ScriptUtils.splitSqlScript(EncodedResource resource, String, String, String, String, String, List<String>) which finds a block-comment-open delimiter but doesn't find a corresponding block-comment-end delimiter. Which then causes the error listed above.
Effectively, it appears that code allows the block-comment end-delimiter to itself be commented-away by a single-line comment prefix. This is not the behavior we see in standard SQL which allows
I forked and fixed this in the following commits:
5488b2004 - Failing test that demonstrates this issue.
changed the title [-]ScriptUtils[/-][+]ScriptUtils fails if the sequence '--' occurs within a multi-line comment and on the same line as '*/'[/+]on Feb 8, 2019
A valid point indeed, are your fix looks good to me. Would you mind preparing a pull request, ideally based on the 5.1.x branch? I'd be happy to merge it right away then, right in time for the 5.1.5 release next week.
Activity
[-]ScriptUtils[/-][+]ScriptUtils fails if the sequence '--' occurs within a multi-line comment and on the same line as '*/'[/+]jhoeller commentedon Feb 8, 2019
A valid point indeed, are your fix looks good to me. Would you mind preparing a pull request, ideally based on the 5.1.x branch? I'd be happy to merge it right away then, right in time for the 5.1.5 release next week.
mmustaquim commentedon Feb 8, 2019
There you go: pull request created. Took me a while to figure out how to move the changes to 5.1.x. Hope this helps.
jhoeller commentedon Feb 8, 2019
Superseded by #22392
sbrannen commentedon Feb 8, 2019
Good catch and analysis, @mmustaquim!
And thanks for providing the fix as well.
mmustaquim commentedon Feb 8, 2019
I'm glad to be able to help. And now looking forward to moving to 5.1.5 next week :-)