Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Binary file modified data/no-dbf.shp
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you let us know how you generated this file
as you know recently there was a big incident at xz with data test files

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this file had to be changed?

Copy link
Contributor

@liviuconcioiu liviuconcioiu Nov 16, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@williamdes I don't think it was generated, but copied from somewhere else. I do see this file signature goes back to 2015. https://www.virustotal.com/gui/file/0249c1f84a8394f24dccf5db8fdc8fbe6663b5f3c1b686f3a162288590d18c66

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi guys.

no-dbf.shp was there before I opened my PR but it was just an empty file (file on master).

My PR allows opening a file with no dbf but since no-dbf-shp was empty I had another error because code was complaining, rightfully so, that no-dbf.shp was not a valid shapefile (no headers to be found).
To remedy that I just duplicated mexico.shp and renamed it no-dbf.shp.

Binary file not shown.
1 change: 0 additions & 1 deletion psalm-baseline.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
<code><![CDATA[$this->records[$index]->getContentLength()]]></code>
</PossiblyNullOperand>
<PossiblyUnusedReturnValue>
<code><![CDATA[bool]]></code>
<code><![CDATA[bool]]></code>
<code><![CDATA[int]]></code>
</PossiblyUnusedReturnValue>
Expand Down
16 changes: 16 additions & 0 deletions src/ShapeFile.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,11 @@

use function chr;
use function count;
use function dbase_close;
use function dbase_create;
use function dbase_delete_record;
use function dbase_open;
use function dbase_pack;
use function extension_loaded;
use function fclose;
use function feof;
Expand Down Expand Up @@ -76,6 +81,8 @@
/** @var array<int, ShapeRecord> */
public array $records = [];

private bool $allowNoDbf = false;

/**
* Checks whether dbase manipulations are supported.
*/
Expand All @@ -101,6 +108,11 @@
) {
}

public function setAllowNoDbf(bool $allowNoDbf): void
{
$this->allowNoDbf = $allowNoDbf;
}

/**
* Loads shapefile and dbase (if supported).
*
Expand Down Expand Up @@ -613,6 +625,10 @@

$dbfName = $this->getFilename('.dbf');
if (! is_readable($dbfName)) {
if ($this->allowNoDbf) {
return true;
}

$this->setError(sprintf('It wasn\'t possible to find the DBase file "%s"', $dbfName));

return false;
Expand Down Expand Up @@ -654,7 +670,7 @@
*
* @param int<0, max> $bytes
*/
public function readSHP(int $bytes): string|false

Check failure on line 673 in src/ShapeFile.php

View workflow job for this annotation

GitHub Actions / lint-docs

int<min,max> has not the correct format on "PhpMyAdmin\ShapeFile\ShapeFile::readSHP"
{
if ($this->shpFile === false) {
return false;
Expand Down
4 changes: 4 additions & 0 deletions src/ShapeRecord.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,10 @@

use function array_values;
use function count;
use function dbase_add_record;
use function dbase_get_record_with_names;
use function dbase_numrecords;
use function dbase_replace_record;
use function fwrite;
use function in_array;
use function is_array;
Expand Down
11 changes: 11 additions & 0 deletions tests/ShapeFileTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -418,4 +418,15 @@ public function testSearch(): void
$shp->getIndexFromDBFData('CNTRY_NAME', 'Czech Republic'),
);
}

public function testAllowsNoDbf(): void
{
if (! ShapeFile::supportsDbase()) {
self::markTestSkipped();
}

$shp = new ShapeFile(ShapeType::Null);
$shp->setAllowNoDbf(true);
self::assertTrue($shp->loadFromFile('data/no-dbf.*'));
}
}
Loading