|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2008-09-01 13:10 UTC] skrald at amossen dot dk
Description:
------------
Calling pg_unescape_bytea() on some data that has been escaped with pg_escape_bytea() does not produce the original data as expected. That is: the "unescape" method is not the opposite of the "escape" method.
Reproduce code:
---------------
<?php
$data = file_get_contents("/path/to/binary/file");
$esc = pg_escape_bytea($data);
$unesc = pg_unescape_bytea($esc);
print($unesc == $data ? "equal" : "different");
?>
Expected result:
----------------
"equal"
Actual result:
--------------
"different"
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Tue Oct 28 03:00:02 2025 UTC |
not a PHP issue, using the libpg API directly from C shows the same issue: -------- pgtest.c ----------------- #include <stdlib.h> #include <stdio.h> #include <libpq-fe.h> int main() { unsigned char from[2] = "\0\t", *to, *to2; size_t from_len = 2, to_len, to2_len; to = PQescapeBytea(from, from_len, &to_len); to2 = PQunescapeBytea(to, &to2_len); printf("'%s' '%s' (%d)\n", to, to2, to2_len); return 0; } ------- result ------------------ '\\000\\011' '\000\011' (8)