From b4aa6ec787876b66d50254119cfa0ad105b844b8 Mon Sep 17 00:00:00 2001 From: AlexeyDsov Date: Mon, 6 Aug 2012 15:13:40 +0400 Subject: [PATCH] fix incorrect bytea escaping for Postgres 9.1+ --- core/DB/PostgresDialect.class.php | 11 ++++++++++- doc/ChangeLog | 5 +++++ 2 files changed, 15 insertions(+), 1 deletion(-) diff --git a/core/DB/PostgresDialect.class.php b/core/DB/PostgresDialect.class.php index e11cb20713..0d4a437489 100644 --- a/core/DB/PostgresDialect.class.php +++ b/core/DB/PostgresDialect.class.php @@ -72,7 +72,16 @@ public static function prepareFullText(array $words, $logic) public function quoteBinary($data) { - return "E'".pg_escape_bytea($data)."'"; + $esc = pg_escape_bytea($data); + if (mb_strpos($esc, '\\x') === 0) { + // http://www.postgresql.org/docs/9.1/static/datatype-binary.html + // if pg_escape_bytea use postgres 9.1+ it's return value like '\x00aabb' (new bytea hex format), + // but must return '\\x00aabb'. So we use this fix:' + return "E'\\".$esc."'"; + } else { + //if function escape value like '\\000\\123' - all ok + return "E'".$esc."'"; + } } public function unquoteBinary($data) diff --git a/doc/ChangeLog b/doc/ChangeLog index 6b93e57a8f..9181249cb1 100644 --- a/doc/ChangeLog +++ b/doc/ChangeLog @@ -1,3 +1,8 @@ +2012-08-10 Alexey S. Denisov + + * core/DB/PostgresDialect.class.php: + fix incorrect bytea escaping for Postgres 9.1+ + 2012-08-10 Alexey S. Denisov * core/Form/Primitives/PrimitiveHstore.class.php: