From 194de05f9e58aa4e6d69a4364fe28ef6189dbdbf Mon Sep 17 00:00:00 2001 From: zak39 Date: Mon, 2 Dec 2024 17:45:49 +0100 Subject: [PATCH] fix: Automatic detection of line endings (CR, CRLF, LF, etc.) --- lib/Files/FileUploader.php | 5 +++++ lib/Files/NextcloudFile.php | 5 +++++ 2 files changed, 10 insertions(+) diff --git a/lib/Files/FileUploader.php b/lib/Files/FileUploader.php index c21ad1aae..7a774da18 100644 --- a/lib/Files/FileUploader.php +++ b/lib/Files/FileUploader.php @@ -5,6 +5,8 @@ class FileUploader implements FileInterface { private $resource; + private string|false $lineEnding; + public function __construct(private string $path) { } @@ -13,6 +15,8 @@ public function __construct(private string $path) { * @throws \Exception */ public function open(?string $path = null) { + $this->lineEnding = ini_get("auto_detect_line_endings"); + ini_set("auto_detect_line_endings", true); $this->resource = fopen($this->path, "r"); if (!$this->resource) { @@ -23,6 +27,7 @@ public function open(?string $path = null) { } public function close(): bool { + ini_set("auto_detect_line_endings", $this->lineEnding); return fclose($this->resource); } diff --git a/lib/Files/NextcloudFile.php b/lib/Files/NextcloudFile.php index 44ced4f4d..2f4f90e06 100644 --- a/lib/Files/NextcloudFile.php +++ b/lib/Files/NextcloudFile.php @@ -6,6 +6,8 @@ class NextcloudFile implements FileInterface { private $resource; + + private string|false $lineEnding; public function __construct(private Node $file) { } @@ -15,6 +17,8 @@ public function __construct(private Node $file) { * @throws \Exception */ public function open(?string $path = null) { + $this->lineEnding = ini_get("auto_detect_line_endings"); + ini_set("auto_detect_line_endings", true); $store = $this->file->getStorage(); $this->resource = $store->fopen($this->file->getInternalPath(), "r"); @@ -26,6 +30,7 @@ public function open(?string $path = null) { } public function close(): bool { + ini_set("auto_detect_line_endings", $this->lineEnding); return fclose($this->resource); }