summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--lib/SqlFormatter.php15
-rw-r--r--tests/clihighlight.html8
-rw-r--r--tests/compress.html4
-rw-r--r--tests/format-highlight.html8
-rw-r--r--tests/format.html7
-rw-r--r--tests/highlight.html5
-rw-r--r--tests/sql.sql2
7 files changed, 34 insertions, 15 deletions
diff --git a/lib/SqlFormatter.php b/lib/SqlFormatter.php
index 24f2968..82927e4 100644
--- a/lib/SqlFormatter.php
+++ b/lib/SqlFormatter.php
@@ -9,7 +9,7 @@
* @copyright 2013 Jeremy Dorn
* @license http://opensource.org/licenses/MIT
* @link http://github.com/jdorn/sql-formatter
- * @version 1.2.17
+ * @version 1.2.18
*/
class SqlFormatter
{
@@ -102,7 +102,7 @@ class SqlFormatter
);
// Punctuation that can be used as a boundary between other tokens
- protected static $boundaries = array(',', ';',':', ']', '[', ')', '(', '.', '=', '<', '>', '+', '-', '*', '/', '!', '^', '%', '|', '&', '#');
+ protected static $boundaries = array(',', ';',':', ')', '(', '.', '=', '<', '>', '+', '-', '*', '/', '!', '^', '%', '|', '&', '#');
// For HTML syntax highlighting
// Styles applied to different token types
@@ -235,9 +235,9 @@ class SqlFormatter
}
// Quoted String
- if ($string[0]==='"' || $string[0]==='\'' || $string[0]==='`') {
+ if ($string[0]==='"' || $string[0]==='\'' || $string[0]==='`' || $string[0]==='[') {
$return = array(
- self::TOKEN_TYPE => ($string[0]==='`'? self::TOKEN_TYPE_BACKTICK_QUOTE : self::TOKEN_TYPE_QUOTE),
+ self::TOKEN_TYPE => (($string[0]==='`' || $string[0]==='[')? self::TOKEN_TYPE_BACKTICK_QUOTE : self::TOKEN_TYPE_QUOTE),
self::TOKEN_VALUE => self::getQuotedString($string)
);
@@ -335,9 +335,10 @@ class SqlFormatter
// This checks for the following patterns:
// 1. backtick quoted string using `` to escape
- // 2. double quoted string using "" or \" to escape
- // 3. single quoted string using '' or \' to escape
- if ( preg_match('/^(((`[^`]*($|`))+)|(("[^"\\\\]*(?:\\\\.[^"\\\\]*)*("|$))+)|((\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*(\'|$))+))/s', $string, $matches)) {
+ // 2. square bracket quoted string (SQL Server) using ]] to escape
+ // 3. double quoted string using "" or \" to escape
+ // 4. single quoted string using '' or \' to escape
+ if ( preg_match('/^(((`[^`]*($|`))+)|((\[[^\]]*($|\]))(\][^\]]*($|\]))*)|(("[^"\\\\]*(?:\\\\.[^"\\\\]*)*("|$))+)|((\'[^\'\\\\]*(?:\\\\.[^\'\\\\]*)*(\'|$))+))/s', $string, $matches)) {
$ret = $matches[1];
}
diff --git a/tests/clihighlight.html b/tests/clihighlight.html
index 6ccfc12..575bc0e 100644
--- a/tests/clihighlight.html
+++ b/tests/clihighlight.html
@@ -805,5 +805,9 @@
@"weird variable name";
SELECT
- "no closing quote
- \ No newline at end of file
+ "no closing quote
+
+SELECT
+ [sqlserver]
+FROM
+ [escap[e]]d style]; \ No newline at end of file
diff --git a/tests/compress.html b/tests/compress.html
index bb2fcf7..e8c6fe6 100644
--- a/tests/compress.html
+++ b/tests/compress.html
@@ -74,4 +74,6 @@ SELECT @ and b;
SELECT @"weird variable name";
-SELECT "no closing quote \ No newline at end of file
+SELECT "no closing quote
+
+SELECT [sqlserver] FROM [escap[e]]d style]; \ No newline at end of file
diff --git a/tests/format-highlight.html b/tests/format-highlight.html
index 73af253..3009897 100644
--- a/tests/format-highlight.html
+++ b/tests/format-highlight.html
@@ -805,5 +805,9 @@
<span style="color: orange;">@&quot;weird variable name&quot;</span><span >;</span></pre>
<pre style="color: black; background-color: white;"><span style="font-weight:bold;">SELECT</span>
- <span style="color: blue;">&quot;no closing quote
-</span></pre> \ No newline at end of file
+ <span style="color: blue;">&quot;no closing quote</span></pre>
+
+<pre style="color: black; background-color: white;"><span style="font-weight:bold;">SELECT</span>
+ <span style="color: purple;">[sqlserver]</span>
+<span style="font-weight:bold;">FROM</span>
+ <span style="color: purple;">[escap[e]]d style]</span><span >;</span></pre> \ No newline at end of file
diff --git a/tests/format.html b/tests/format.html
index dcbac03..d2ea31e 100644
--- a/tests/format.html
+++ b/tests/format.html
@@ -804,4 +804,9 @@ SELECT
@"weird variable name";
SELECT
- "no closing quote \ No newline at end of file
+ "no closing quote
+
+SELECT
+ [sqlserver]
+FROM
+ [escap[e]]d style]; \ No newline at end of file
diff --git a/tests/highlight.html b/tests/highlight.html
index e26af9a..4637eee 100644
--- a/tests/highlight.html
+++ b/tests/highlight.html
@@ -258,5 +258,6 @@
<pre style="color: black; background-color: white;"><span style="font-weight:bold;">SELECT</span> <span style="color: orange;">@&quot;weird variable name&quot;</span><span >;</span></pre>
-<pre style="color: black; background-color: white;"><span style="font-weight:bold;">SELECT</span> <span style="color: blue;">&quot;no closing quote
-</span></pre> \ No newline at end of file
+<pre style="color: black; background-color: white;"><span style="font-weight:bold;">SELECT</span> <span style="color: blue;">&quot;no closing quote</span></pre>
+
+<pre style="color: black; background-color: white;"><span style="font-weight:bold;">SELECT</span> <span style="color: purple;">[sqlserver]</span> <span style="font-weight:bold;">FROM</span> <span style="color: purple;">[escap[e]]d style]</span><span >;</span></pre> \ No newline at end of file
diff --git a/tests/sql.sql b/tests/sql.sql
index 4e2d988..7bd40c0 100644
--- a/tests/sql.sql
+++ b/tests/sql.sql
@@ -259,3 +259,5 @@ SELECT @ and b;
SELECT @"weird variable name";
SELECT "no closing quote
+
+SELECT [sqlserver] FROM [escap[e]]d style];