cvs: php4(PHP_4_2_0) /ext/pgsql pgsql.c /ext/pgsql/tests 08escape.phpt escape.inc

From: Date: Thu, 04 Apr 2002 15:29:35 +0000
Subject: cvs: php4(PHP_4_2_0) /ext/pgsql pgsql.c /ext/pgsql/tests 08escape.phpt escape.inc
Groups: php.cvs 
Request: Send a blank email to php-cvs+get-10864@lists.php.net to get a copy of this message
yohgaki Thu Apr 4 10:29:35 2002 EDT Added files: (Branch: PHP_4_2_0) /php4/ext/pgsql/tests 08escape.phpt escape.inc Modified files: /php4/ext/pgsql pgsql.c Log: MFH # Fixed crash with pg_escape_*() # Added test for pg_escape_*() Index: php4/ext/pgsql/pgsql.c diff -u php4/ext/pgsql/pgsql.c:1.150.2.3 php4/ext/pgsql/pgsql.c:1.150.2.4 --- php4/ext/pgsql/pgsql.c:1.150.2.3 Sat Mar 30 18:23:58 2002 +++ php4/ext/pgsql/pgsql.c Thu Apr 4 10:29:34 2002 @@ -19,7 +19,7 @@ +----------------------------------------------------------------------+ */ -/* $Id: pgsql.c,v 1.150.2.3 2002/03/30 23:23:58 yohgaki Exp $ */ +/* $Id: pgsql.c,v 1.150.2.4 2002/04/04 15:29:34 yohgaki Exp $ */ #include <stdlib.h> @@ -2376,17 +2376,15 @@ PHP_FUNCTION(pg_escape_string) { char *from = NULL, *to = NULL; - int len; + size_t from_len, to_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", - &from, &len) == FAILURE) { + &from, &from_len) == FAILURE) { return; } - len = (int)PQescapeString(to, from, strlen(from)); - if (len < 0) { - RETURN_FALSE; - } - RETURN_STRINGL(to, len, 0); + to = (char *)emalloc(from_len*2+1); + to_len = (int)PQescapeString(to, from, from_len); + RETURN_STRINGL(to, to_len, 0); } /* }}} */ @@ -2395,17 +2393,15 @@ PHP_FUNCTION(pg_escape_bytea) { char *from = NULL, *to = NULL; - int len; + size_t from_len, to_len; if (zend_parse_parameters(ZEND_NUM_ARGS() TSRMLS_CC, "s", - &from, &len) == FAILURE) { + &from, &from_len) == FAILURE) { return; } - to = (char *)PQescapeBytea((unsigned char*)from, strlen(from), (size_t *)&len); - if (len < 0) { - RETURN_FALSE; - } - RETURN_STRINGL(to, len, 0); + to = (char *)PQescapeBytea((unsigned char*)from, from_len, &to_len); + RETVAL_STRINGL(to, to_len-1, 1); + free(to); } /* }}} */ #endif Index: php4/ext/pgsql/tests/08escape.phpt +++ php4/ext/pgsql/tests/08escape.phpt --TEST-- PostgreSQL escape functions --SKIPIF-- <?php include("skipif.inc"); ?> --FILE-- <?php include("escape.inc"); ?> --EXPECT-- OK Index: php4/ext/pgsql/tests/escape.inc +++ php4/ext/pgsql/tests/escape.inc <?php $before = "ABC\\ABC"; $expect = "ABC\\\\ABC"; $after = pg_escape_string($before); if ($expect === $after) { echo "pg_escpae_string() is Ok\n"; } else { echo "pg_escpae_string() is NOT Ok\n"; var_dump($before); var_dump($after); var_dump($expect); } $before = "ABC\\ABC"; $expect = "ABC\\\\\\\\ABC"; $after = pg_escape_bytea($before); if ($expect === $after) { echo "pg_escpae_byte() is Ok\n"; } else { echo "pg_escpae_byte() is NOT Ok\n"; var_dump($before); var_dump($after); var_dump($expect); } ?>

« previous php.cvs (#10864) next »