Skip to content

Commit

Permalink
Change back and enhance style comments handling
Browse files Browse the repository at this point in the history
Change back to before previous commit, so c style comments are handled
again, but add exceptions for mysql specials
  • Loading branch information
richard67 committed Mar 14, 2016
1 parent 3b942a8 commit d13ad7f
Showing 1 changed file with 21 additions and 8 deletions.
29 changes: 21 additions & 8 deletions libraries/joomla/database/driver.php
Expand Up @@ -332,7 +332,7 @@ public static function getInstance($options = array())

/**
* Splits a string of multiple queries into an array of individual queries.
* Comments after "--" or "#" are stripped off if not within quoted text.
* Single line or line end comments and multi line comments are stripped off.
*
* @param string $sql Input SQL string with which to split into individual queries.
*
Expand All @@ -345,7 +345,7 @@ public static function splitSql($sql)
$open = false;
$comment = false;
$endComment = false;
$char = '';
$endString = '';
$end = strlen($sql);
$queries = array();
$query = '';
Expand All @@ -355,10 +355,13 @@ public static function splitSql($sql)
$current = substr($sql, $i, 1);
$current2 = substr($sql, $i, 2);
$current3 = substr($sql, $i, 3);
$lenEndString = strlen($endString);
$testEnd = substr($sql, $i, $lenEndString);

if ($current == '"' || $current == "'" || $current2 == '--'
|| ($current2 == '/*' && $current3 != '/*!' && $current3 != '/*+')
|| ($current == '#' && $current3 != '#__')
|| ($comment && $current == $char))
|| ($comment && $testEnd == $endString))
{
// Check if quoted with previous backslash
$n = 2;
Expand All @@ -373,33 +376,43 @@ public static function splitSql($sql)
{
if ($open)
{
if ($current == $char)
if ($testEnd == $endString)
{
if ($comment)
{
$comment = false;
$endComment = true;
if ($lenEndString > 1)
{
$i += ($lenEndString - 1);
$current = substr($sql, $i, 1);
}
}
$open = false;
$char = '';
$endString = '';
}
}
else
{
$open = true;
if ($current2 == '--')
{
$char = "\n";
$endString = "\n";
$comment = true;
}
elseif ($current2 == '/*')
{
$endString = '*/';
$comment = true;
}
elseif ($current == '#')
{
$char = "\n";
$endString = "\n";
$comment = true;
}
else
{
$char = $current;
$endString = $current;
}
}
}
Expand Down

0 comments on commit d13ad7f

Please sign in to comment.