Skip to content

ScriptUtils fails if the sequence '--' occurs within a multi-line comment and on the same line as '*/' #22388

Closed

Description

@mmustaquim

Affects: 5.1.4

Bug Description

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.
  • a320f622bc - The fix I ended up using.

Activity

  1. added
    status: waiting-for-triage
    on Feb 8, 2019
  2. 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
  3. self-assigned this
    on Feb 8, 2019
  4. added
    type: enhancement
    and removed
    status: waiting-for-triage
    on Feb 8, 2019
  5. added this to the 5.1.5 milestone on Feb 8, 2019
  6. jhoeller commented on Feb 8, 2019

    @jhoeller
    Contributor

    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.

  7. mmustaquim commented on Feb 8, 2019

    @mmustaquim
    ContributorAuthor

    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.

  8. removed this from the 5.1.5 milestone on Feb 8, 2019
  9. jhoeller commented on Feb 8, 2019

    @jhoeller
    Contributor

    Superseded by #22392

  10. added
    status: superseded
    on Feb 8, 2019
  11. sbrannen commented on Feb 8, 2019

    @sbrannen
    Member

    Good catch and analysis, @mmustaquim!

    And thanks for providing the fix as well.

  12. mmustaquim commented on Feb 8, 2019

    @mmustaquim
    ContributorAuthor

    I'm glad to be able to help. And now looking forward to moving to 5.1.5 next week :-)

  13. added
    in: data
    on Jun 29, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

in: datastatus: supersededtype: enhancement

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions