mirror of
https://github.com/php/php-src.git
synced 2025-08-15 21:48:51 +02:00
Merge branch 'PHP-8.4'
This commit is contained in:
commit
50bffd3284
2 changed files with 27 additions and 2 deletions
|
@ -3390,11 +3390,12 @@ static zend_result pgsql_copy_from_query(PGconn *pgsql, PGresult *pgsql_result,
|
|||
if (UNEXPECTED(!tmp)) {
|
||||
return FAILURE;
|
||||
}
|
||||
zend_string *zquery = zend_string_alloc(ZSTR_LEN(tmp) + 1, false);
|
||||
zend_string *zquery = zend_string_alloc(ZSTR_LEN(tmp) + 2, false);
|
||||
memcpy(ZSTR_VAL(zquery), ZSTR_VAL(tmp), ZSTR_LEN(tmp) + 1);
|
||||
ZSTR_LEN(zquery) = ZSTR_LEN(tmp);
|
||||
if (ZSTR_LEN(tmp) > 0 && ZSTR_VAL(zquery)[ZSTR_LEN(tmp)] != '\n') {
|
||||
if (ZSTR_LEN(tmp) > 0 && ZSTR_VAL(zquery)[ZSTR_LEN(tmp) - 1] != '\n') {
|
||||
ZSTR_VAL(zquery)[ZSTR_LEN(tmp)] = '\n';
|
||||
ZSTR_VAL(zquery)[ZSTR_LEN(tmp) + 1] = '\0';
|
||||
ZSTR_LEN(zquery) ++;
|
||||
}
|
||||
if (PQputCopyData(pgsql, ZSTR_VAL(zquery), ZSTR_LEN(zquery)) != 1) {
|
||||
|
|
24
ext/pgsql/tests/gh18148.phpt
Normal file
24
ext/pgsql/tests/gh18148.phpt
Normal file
|
@ -0,0 +1,24 @@
|
|||
--TEST--
|
||||
Fix GH-18148 pg_copy_from() command position offset when giving explicit \n terminator
|
||||
--EXTENSIONS--
|
||||
pgsql
|
||||
--SKIPIF--
|
||||
<?php
|
||||
include("inc/skipif.inc");
|
||||
?>
|
||||
--FILE--
|
||||
<?php
|
||||
|
||||
include "inc/config.inc";
|
||||
$table_name = "gh18148";
|
||||
$db = pg_connect($conn_str);
|
||||
pg_query($db, "CREATE TABLE {$table_name} (a integer, b text)");
|
||||
var_dump(pg_copy_from( $db, $table_name, [ "1\tone\n" ] ));
|
||||
--CLEAN--
|
||||
<?php
|
||||
include('inc/config.inc');
|
||||
$db = pg_connect($conn_str);
|
||||
pg_query($db, "DROP TABLE IF EXISTS gh18148 cascade");
|
||||
?>
|
||||
--EXPECT--
|
||||
bool(true)
|
Loading…
Add table
Add a link
Reference in a new issue