summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichal Čihař <michal@cihar.com>2016-09-20 08:53:54 +0200
committerMichal Čihař <michal@cihar.com>2016-09-20 08:53:54 +0200
commitc543b67d4e5fb9cafabe1b0ef304c824d0f24a25 (patch)
tree4e72d9297be6106df678437645036a463d727a8c
parenta483d102eba78bed67ebcf713c3885c4302f3e73 (diff)
downloadsql-parser-c543b67d4e5fb9cafabe1b0ef304c824d0f24a25.zip
sql-parser-c543b67d4e5fb9cafabe1b0ef304c824d0f24a25.tar.gz
sql-parser-c543b67d4e5fb9cafabe1b0ef304c824d0f24a25.tar.bz2
Fixed escaping of control chars in CLI formatter
Fixes #84 Signed-off-by: Michal Čihař <michal@cihar.com>
-rw-r--r--CHANGELOG.md1
-rw-r--r--src/Utils/Formatter.php25
2 files changed, 24 insertions, 2 deletions
diff --git a/CHANGELOG.md b/CHANGELOG.md
index 4490ae7..013e389 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,7 @@
* Fix parsing of DEFINER without backquotes
* Fixed escaping HTML entities in HTML formatter
+* Fixed escaping of control chars in CLI formatter
## [3.4.6] - 2016-09-13
diff --git a/src/Utils/Formatter.php b/src/Utils/Formatter.php
index 9804580..41b5094 100644
--- a/src/Utils/Formatter.php
+++ b/src/Utils/Formatter.php
@@ -430,6 +430,27 @@ class Formatter
return $ret;
}
+ public function escapeConsole($string)
+ {
+ return str_replace(
+ array(
+ "\x00", "\x01", "\x02", "\x03", "\x04",
+ "\x05", "\x06", "\x07", "\x08", "\x09", "\x0A",
+ "\x0B","\x0C","\x0D", "\x0E", "\x0F", "\x10", "\x11",
+ "\x12","\x13","\x14","\x15", "\x16", "\x17", "\x18",
+ "\x19","\x1A","\x1B","\x1C","\x1D", "\x1E", "\x1F"
+ ),
+ array(
+ '\x00', '\x01', '\x02', '\x03', '\x04',
+ '\x05', '\x06', '\x07', '\x08', '\x09', '\x0A',
+ '\x0B', '\x0C', '\x0D', '\x0E', '\x0F', '\x10', '\x11',
+ '\x12', '\x13', '\x14', '\x15', '\x16', '\x17', '\x18',
+ '\x19', '\x1A', '\x1B', '\x1C', '\x1D', '\x1E', '\x1F'
+ ),
+ $string
+ );
+ }
+
/**
* Tries to print the query and returns the result.
*
@@ -455,7 +476,7 @@ class Formatter
if ($this->options['type'] === 'html') {
return '<span ' . $format['html'] . '>' . htmlspecialchars($text, ENT_NOQUOTES) . '</span>';
} elseif ($this->options['type'] === 'cli') {
- return $format['cli'] . $text;
+ return $format['cli'] . $this->escapeConsole($text);
}
break;
@@ -463,7 +484,7 @@ class Formatter
}
if ($this->options['type'] === 'cli') {
- return "\x1b[39m" . $text;
+ return "\x1b[39m" . $this->escapeConsole($text);
} elseif ($this->options['type'] === 'html') {
return htmlspecialchars($text, ENT_NOQUOTES);
}