Skip to content

Commit 0434141

Browse files
committed
Fixed bug #77047 pg_convert has a broken regex for the 'TIME WITHOUT TIMEZONE' data type
Backport 369c991 and 282a63d to 7.1, closes #3634
1 parent a56cdd0 commit 0434141

File tree

2 files changed

+41
-1
lines changed

2 files changed

+41
-1
lines changed

ext/pgsql/pgsql.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6267,7 +6267,7 @@ PHP_PGSQL_API int php_pgsql_convert(PGconn *pg_link, const char *table_name, con
62676267
}
62686268
else {
62696269
/* FIXME: better regex must be used */
6270-
if (php_pgsql_convert_match(Z_STRVAL_P(val), Z_STRLEN_P(val), "^(([0-9]{1,2}:[0-9]{1,2}){1}(:[0-9]{1,2}){0,1})){0,1}$", 1) == FAILURE) {
6270+
if (php_pgsql_convert_match(Z_STRVAL_P(val), Z_STRLEN_P(val), "^(([0-9]{1,2}:[0-9]{1,2}){1}(:[0-9]{1,2}){0,1}){0,1}$", 1) == FAILURE) {
62716271
err = 1;
62726272
}
62736273
else {

ext/pgsql/tests/bug77047.phpt

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
--TEST--
2+
Bug #77047 pg_insert has a broken regex for the 'TIME WITHOUT TIMEZONE' data type
3+
--SKIPIF--
4+
<?php
5+
include("skipif.inc");
6+
?>
7+
--FILE--
8+
<?php
9+
error_reporting(E_ALL);
10+
11+
include 'config.inc';
12+
13+
$db = pg_connect($conn_str);
14+
15+
pg_query($db, "DROP TABLE IF EXISTS bug77047");
16+
pg_query($db, "CREATE TABLE bug77047 (
17+
t TIME WITHOUT TIME ZONE
18+
)");
19+
20+
pg_insert($db, "bug77047", array("t" => "13:31"));
21+
pg_insert($db, "bug77047", array("t" => "13:31:13"));
22+
pg_insert($db, "bug77047", array("t" => "1:2:3"));
23+
pg_insert($db, "bug77047", array("t" => "xyz"));
24+
pg_insert($db, "bug77047", array("t" => NULL));
25+
pg_insert($db, "bug77047", array("t" => ""));
26+
27+
$res = pg_query($db, "SELECT t FROM bug77047");
28+
while (false !== ($row = pg_fetch_row($res))) {
29+
var_dump(array_pop($row));
30+
}
31+
32+
?>
33+
--EXPECTF--
34+
Notice: pg_insert(): Expects NULL or string for PostgreSQL time field (t) in %s on line %d
35+
string(8) "13:31:00"
36+
string(8) "13:31:13"
37+
string(8) "01:02:03"
38+
NULL
39+
NULL
40+

0 commit comments

Comments
 (0)