com php-src: Fix #70825: Cannot fetch multiple values with group in ini file: NEWS ext/dba/libinifile/inifile.c ext/dba/tests/bug70825.phpt
| From: | Christoph Michael Becker | Date: | Thu, 25 Aug 2016 16:18:10 +0000 |
| Subject: | com php-src: Fix #70825: Cannot fetch multiple values with group in ini file: NEWS ext/dba/libinifile/inifile.c ext/dba/tests/bug70825.phpt | ||
| Groups: | php.cvs | ||
| Request: | Send a blank email to php-cvs+get-94065@lists.php.net to get a copy of this message | ||
Commit: 84512a117789563a64172115c648944538006a69
Author: Christoph M. Becker <cmbecker69@gmx.de> Thu, 25 Aug 2016 18:10:38 +0200
Parents: bd8112afe076cd975fbfcf82b659f6420317de70
Branches: PHP-5.6 PHP-7..0 PHP-7.1 master
Link: http://git.php.net/?p=php-src.git;a=commitdiff;h=84512a117789563a64172115c648944538006a69
Log:
Fix #70825: Cannot fetch multiple values with group in ini file
If we have the position already from the last fetch, we also have to preset
the current group, because it won't be read again.
Bugs:
https://bugs.php.net/70825
Changed paths:
M NEWS
M ext/dba/libinifile/inifile.c
A ext/dba/tests/bug70825.phpt
Diff:
diff --git a/NEWS b/NEWS
index 9c3cef5..a7a58b6 100644
--- a/NEWS
+++ b/NEWS
@@ -9,6 +9,8 @@ PHP NEWS
- Dba:
. Fixed bug #71514 (Bad dba_replace condition because of wrong API usage).
(cmb)
+ . Fixed bug #70825 (Cannot fetch multiple values with group in ini file).
+ (cmb)
- Streams:
. Fixed bug #72853 (stream_set_blocking doesn't work). (Laruence)
diff --git a/ext/dba/libinifile/inifile.c b/ext/dba/libinifile/inifile.c
index 9f1789b..95ac9a8 100644
--- a/ext/dba/libinifile/inifile.c
+++ b/ext/dba/libinifile/inifile.c
@@ -250,6 +250,7 @@ val_type inifile_fetch(inifile *dba, const key_type *key, int skip TSRMLS_DC) {
if (skip == -1 && dba->next.key.group && dba->next.key.name &&
!inifile_key_cmp(&dba->next..key, key TSRMLS_CC)) {
/* we got position already from last fetch */
php_stream_seek(dba->fp, dba->next.pos, SEEK_SET);
+ ln..key.group = estrdup(dba->next.key.group);
} else {
/* specific instance or not same key -> restart search */
/* the slow way: restart and seacrch */
diff --git a/ext/dba/tests/bug70825.phpt b/ext/dba/tests/bug70825.phpt
new file mode 100644
index 0000000..ff05f01
--- /dev/null
+++ b/ext/dba/tests/bug70825.phpt
@@ -0,0 +1,71 @@
+--TEST--
+Bug #70825 (Cannot fetch multiple values with group in ini file)
+--SKIPIF--
+<?php
+if (!extension_loaded('dba')) die('skip dba extension not available');
+if (!in_array('inifile', dba_handlers())) die('skip inifile handler not
available');
+?>
+--FILE--
+<?php
+$filename = __DIR__ . DIRECTORY_SEPARATOR . 'bug70825.ini';
+
+$db = dba_open($filename, 'n', 'inifile');
+dba_insert('foo', 23, $db);
+dba_insert('foo', 42, $db);
+dba_insert('foo', 1337, $db);
+var_dump(dba_fetch('foo', -1, $db));
+var_dump(dba_fetch('foo', -1, $db));
+var_dump(dba_fetch('foo', -1, $db));
+dba_close($db);
+unlink($filename);
+
+$db = dba_open($filename, 'n', 'inifile');
+dba_insert(['foo', 'bar'], 23, $db);
+dba_insert(['foo', 'bar'], 42, $db);
+dba_insert(['foo', 'bar'], 1337, $db);
+var_dump(dba_fetch(['foo', 'bar'], -1, $db));
+var_dump(dba_fetch(['foo', 'bar'], -1, $db));
+var_dump(dba_fetch(['foo', 'bar'], -1, $db));
+dba_close($db);
+unlink($filename);
+
+$db = dba_open($filename, 'n', 'inifile');
+dba_insert('[foo]bar', 23, $db);
+dba_insert('[foo]bar', 42, $db);
+dba_insert('[foo]bar', 1337, $db);
+var_dump(dba_fetch('[foo]bar', -1, $db));
+var_dump(dba_fetch('[foo]bar', -1, $db));
+var_dump(dba_fetch('[foo]bar', -1, $db));
+dba_close($db);
+unlink($filename);
+
+$db = dba_open($filename, 'n', 'inifile');
+dba_insert('[foo]bar', 23, $db);
+dba_insert('[foo]bar', 42, $db);
+dba_insert('[foo]bar', 1337, $db);
+var_dump(dba_fetch('[foo]bar', 0, $db));
+var_dump(dba_fetch('[foo]bar', 1, $db));
+var_dump(dba_fetch('[foo]bar', 2, $db));
+dba_close($db);
+unlink($filename);
+?>
+==DONE==
+--EXPECT--
+string(2) "23"
+string(2) "42"
+string(4) "1337"
+string(2) "23"
+string(2) "42"
+string(4) "1337"
+string(2) "23"
+string(2) "42"
+string(4) "1337"
+string(2) "23"
+string(2) "42"
+string(4) "1337"
+==DONE==
+--CLEAN--
+<?php
+$filename = __DIR__ . DIRECTORY_SEPARATOR . 'bug70825.ini';
+unlink($filename);
+?>