Framework: [5.2] FilesystemAdapter->append() & prepend() incorrectly add an EOL

Created on 26 Feb 2016  路  5Comments  路  Source: laravel/framework

Refers to branch 5.2.

See these tests:
public function testAppendAddsDataToFile() { file_put_contents(__DIR__.'/file.txt', 'foo'); $files = new FilesystemAdapter( new Flysystem( new LocalAdapter('/', LOCK_EX, LocalAdapter::DISALLOW_LINKS, []), null ) ); $bytesWritten = $files->append(__DIR__.'/file.txt', 'bar'); $this->assertEquals(mb_strlen('bar', '8bit'), $bytesWritten); $this->assertFileExists(__DIR__.'/file.txt'); $this->assertStringEqualsFile(__DIR__.'/file.txt', 'foobar'); @unlink(__DIR__.'/file.txt'); } public function testPrependExistingFiles() { $files = new FilesystemAdapter( new Flysystem( new LocalAdapter('/', LOCK_EX, LocalAdapter::DISALLOW_LINKS, []), null ) ); $files->put(__DIR__.'/file.txt', 'World'); $files->prepend(__DIR__.'/file.txt', 'Hello '); $this->assertStringEqualsFile(__DIR__.'/file.txt', 'Hello World'); @unlink(__DIR__.'/file.txt'); }

To solve this we must either change the default value for the seperator param to null (which breaks existing functionality!) or add this parameter to the Illuminate\Contracts\Filesystem\Filesystem (where it is now sadly missing)

All 5 comments

I don't see an issue?

Yes, there is an issue: the test fails.
And having unasked for EOL's added to the file is unwanted, i suppose.

Please re-open

You just need to manually pass a 2nd param if you don't like the default.

True, but that extra parameter is not defined in the interface.

Was this page helpful?
0 / 5 - 0 ratings