From 218446b641a0220bc8e99561fb50c1c810787893 Mon Sep 17 00:00:00 2001 From: Fabian Lemm Date: Wed, 24 Nov 2021 08:32:07 +0100 Subject: [PATCH] trim metadata from windows server #1383 --- src/Adapter/AbstractFtpAdapter.php | 2 +- tests/FtpTests.php | 17 ++++++++++++++++- 2 files changed, 17 insertions(+), 2 deletions(-) diff --git a/src/Adapter/AbstractFtpAdapter.php b/src/Adapter/AbstractFtpAdapter.php index b232cdc4b..25d949ead 100644 --- a/src/Adapter/AbstractFtpAdapter.php +++ b/src/Adapter/AbstractFtpAdapter.php @@ -539,7 +539,7 @@ protected function normalizeWindowsObject($item, $base) */ protected function detectSystemType($item) { - return preg_match('/^[0-9]{2,4}-[0-9]{2}-[0-9]{2}/', $item) ? 'windows' : 'unix'; + return preg_match('/^[0-9]{2,4}-[0-9]{2}-[0-9]{2}/', trim($item)) ? 'windows' : 'unix'; } /** diff --git a/tests/FtpTests.php b/tests/FtpTests.php index 57c0179f5..aa0e651c4 100755 --- a/tests/FtpTests.php +++ b/tests/FtpTests.php @@ -103,6 +103,7 @@ function ftp_chdir($connection, $directory) 'file2.txt', 'file3.txt', 'file4.txt', + 'file5WithPadding.txt', 'dir1', 'file1.with-total-line.txt', 'file1.with-invalid-line.txt', @@ -128,7 +129,7 @@ function ftp_raw($connection, $command) if ($connection === 'utf8.alreadyActive') { return [0 => '202 UTF8 mode is always enabled. No need to send this command.']; } - + return [0 => '200 UTF8 set to on']; } @@ -229,6 +230,12 @@ function ftp_rawlist($connection, $directory) ]; } + if (strpos($directory, 'file5WithPadding.txt') !== false) { + return [ + ' 2016-05-23 12:09PM 685 file5WithPadding.txt', + ]; + } + if (strpos($directory, 'dir1') !== false) { return [ '2015-05-23 12:09 dir1', @@ -568,6 +575,14 @@ public function testGetWindowsMetadata() $this->assertEquals('public', $metadata['visibility']); $this->assertEquals(684, $metadata['size']); + $metadata = $adapter->getMetadata('file5WithPadding.txt'); + $this->assertIsArray($metadata); + $this->assertEquals('file', $metadata['type']); + $this->assertEquals('file5WithPadding.txt', $metadata['path']); + $this->assertEquals(1464005340, $metadata['timestamp']); + $this->assertEquals('public', $metadata['visibility']); + $this->assertEquals(685, $metadata['size']); + $metadata = $adapter->getMetadata('dir1'); $this->assertEquals('dir', $metadata['type']); $this->assertEquals('dir1', $metadata['path']);