Uploaded image for project: 'CiviCRM'
  1. CiviCRM
  2. CRM-18199

CRM_Utils_File::sourceSQLFile too greedy when stripping comments

    Details

    • Type: Bug
    • Status: Done/Fixed
    • Priority: Minor
    • Resolution: Fixed/Completed
    • Affects Version/s: 4.6, 4.7
    • Fix Version/s: 4.7.13
    • Component/s: Core CiviCRM
    • Labels:
    • Versioning Impact:
      Patch (backwards-compatible bug fixes)
    • Documentation Required?:
      None
    • Funding Source:
      Contributed Code

      Description

      This function includes these lines:

          //get rid of comments starting with # and --
      
          $string = preg_replace("/^#[^\n]*$/m", "\n", $string);
          $string = preg_replace("/^(--[^-]).*/m", "\n", $string);
      

      From my testing, it appears this causes the comment AND the next line to be stripped. As a result, this SQL fails, because the CREATE TABLE line is stripped and the query that's executed starts with `id` int(10) ... :

      --
      -- Do something.
      --
      CREATE TABLE IF NOT EXISTS `mytable` (
        `id` int(10) unsigned NOT NULL
      );
      

      The workaround is to add a newline after the third comment, like so:

      --
      -- Do something.
      --
      
      CREATE TABLE IF NOT EXISTS `mytable` (
        `id` int(10) unsigned NOT NULL
      );
      

      I think this is related to the /m regex modifier, but haven't yet got my head around what that modifier does.

        Attachments

        1. qt.php
          0.5 kB
          Giovanni Gargani

          Activity

            People

            • Assignee:
              Unassigned
              Reporter:
              allenshaw Allen Shaw
            • Votes:
              0 Vote for this issue
              Watchers:
              3 Start watching this issue

              Dates

              • Created:
                Updated:
                Resolved: