Skip to content

Commit

Permalink
Merged revision(s) 339849-339851 from pecl/dbase/branches/dbase-5.1:
Browse files Browse the repository at this point in the history
Fix #52112: dbase_get_record() returns integer instead of decimal values

We're going to use zend_strtod() instead of atof() when reading decimal
values from a DBF to avoid any locale specific behavior.


git-svn-id: http://svn.php.net/repository/pecl/dbase/trunk@339852 c90b9560-bf6c-de11-be94-00142212c4b1
  • Loading branch information
cmb69 committed Aug 11, 2016
2 parents 199d43c + 0b9de73 commit 3965e77
Show file tree
Hide file tree
Showing 2 changed files with 66 additions and 4 deletions.
8 changes: 4 additions & 4 deletions dbase.c
Original file line number Diff line number Diff line change
Expand Up @@ -505,17 +505,17 @@ static void php_dbase_get_record(INTERNAL_FUNCTION_PARAMETERS, int assoc)
errno = errno_save;
} else {
if (!assoc) {
add_next_index_double(return_value, atof(str_value));
add_next_index_double(return_value, zend_strtod(str_value, NULL));
} else {
add_assoc_double(return_value, cur_f->db_fname, atof(str_value));
add_assoc_double(return_value, cur_f->db_fname, zend_strtod(str_value, NULL));
}
}
break;
case 'F':
if (!assoc) {
add_next_index_double(return_value, atof(str_value));
add_next_index_double(return_value, zend_strtod(str_value, NULL));
} else {
add_assoc_double(return_value, cur_f->db_fname, atof(str_value));
add_assoc_double(return_value, cur_f->db_fname, zend_strtod(str_value, NULL));
}
break;
case 'L': /* we used to FALL THROUGH, but now we check for T/Y and F/N
Expand Down
62 changes: 62 additions & 0 deletions tests/bug52112.phpt
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
--TEST--
Bug #52112 (dbase_get_record() returns integer instead of decimal value)
--SKIPIF--
<?php
if (!extension_loaded('dbase')) die('skip dbase extension not available');
$locales = array('de_DE.UTF-8', 'de-DE');
if (array_search(setlocale(LC_NUMERIC, $locales), $locales) === false) {
die('skip German locale not available');
}
?>
--FILE--
<?php
$filename = __DIR__ . DIRECTORY_SEPARATOR . 'dbase_get_record_basic.dbf';
copy(__DIR__ . DIRECTORY_SEPARATOR . 'example.dbf', $filename);
setlocale(LC_NUMERIC, 'de_DE.UTF-8', 'de-DE');

$db = dbase_open($filename, 0);
var_dump($db);

var_dump(dbase_get_record($db, 1));
var_dump(dbase_get_record_with_names($db, 1));

var_dump(dbase_close($db));
?>
===DONE===
--EXPECTF--
int(%d)
array(6) {
[0]=>
int(1)
[1]=>
string(25) "dBase III "
[2]=>
string(8) "19840501"
[3]=>
int(1)
[4]=>
float(123,45)
["deleted"]=>
int(0)
}
array(6) {
["ID"]=>
int(1)
["NAME"]=>
string(25) "dBase III "
["RELEASED"]=>
string(8) "19840501"
["SUPORTED"]=>
int(1)
["PRICE"]=>
float(123,45)
["deleted"]=>
int(0)
}
bool(true)
===DONE===
--CLEAN--
<?php
$filename = __DIR__ . DIRECTORY_SEPARATOR . 'dbase_get_record_basic.dbf';
unlink($filename);
?>

0 comments on commit 3965e77

Please sign in to comment.