From 7060eed55109d2a12751eeedb84412093a9223cc Mon Sep 17 00:00:00 2001 From: gam6itko-job-pc Date: Mon, 3 Aug 2020 13:01:13 +0300 Subject: [PATCH] fixed #88 --- src/XBase/Column/DBaseColumn.php | 6 ++++-- src/XBase/Table.php | 2 -- tests/DbfTest.php | 17 +++++++++++++++++ 3 files changed, 21 insertions(+), 4 deletions(-) diff --git a/src/XBase/Column/DBaseColumn.php b/src/XBase/Column/DBaseColumn.php index 59a4914..8153e08 100644 --- a/src/XBase/Column/DBaseColumn.php +++ b/src/XBase/Column/DBaseColumn.php @@ -3,7 +3,6 @@ namespace XBase\Column; use XBase\Enum\FieldType; -use XBase\Record; use XBase\Stream\Stream; class DBaseColumn extends AbstractColumn @@ -40,8 +39,11 @@ public static function create(string $memoryChunk, int $colIndex, ?int $bytePos public function __construct(string $name, string $type, int $memAddress, int $length, int $decimalCount, $reserved1, int $workAreaID, $reserved2, bool $setFields, $reserved3, bool $indexed, int $colIndex, ?int $bytePos = null) { + $name = (false !== strpos($name, chr(0x00))) ? substr($name, 0, strpos($name, chr(0x00))) : $name; + $this->rawName = $name; - $this->name = strtolower(rtrim($name, chr(0x00))); + // chop all garbage from 0x00 + $this->name = strtolower($name); $this->type = $type; $this->memAddress = $memAddress; $this->length = $length; diff --git a/src/XBase/Table.php b/src/XBase/Table.php index aebab9d..d77044f 100755 --- a/src/XBase/Table.php +++ b/src/XBase/Table.php @@ -417,8 +417,6 @@ public function getVersion() /** * @see Codepage - * - * @return int */ public function getLanguageCode(): int { diff --git a/tests/DbfTest.php b/tests/DbfTest.php index 18dec0a..d778b58 100644 --- a/tests/DbfTest.php +++ b/tests/DbfTest.php @@ -3,6 +3,7 @@ namespace XBase\Tests; use XBase\Enum\TableType; +use XBase\Record\DBaseRecord; use XBase\Table; class DbfTest extends AbstractTestCase @@ -18,4 +19,20 @@ public function test2ByteHeaderTerminator(): void self::assertSame([1000, 'Банк ВТБ (ПАО)', 1, 1], array_values($table->nextRecord()->getData())); self::assertSame([990, 'ООО КБ "Дружба"', 1, 1], array_values($table->pickRecord(441)->getData())); } + + public function testIssue88(): void + { + $table = new Table(__DIR__.'/Resources/dbf/cbrf_122019N1.dbf', null, 'cp866'); + /** @var DBaseRecord $record */ + $record = $table->nextRecord(); + self::assertSame( + [ + 'regn' => 1, + 'name_b' => 'АО ЮниКредит Банк', + 'priz' => 1, + 'priz_p' => 1, + ], + $record->getData() + ); + } }