From f8cb5ca21c9a38666134966c59626c82be4a4eaf Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Geoffrey=20=E2=80=9CFrogeye=E2=80=9D=20Preud=27homme?= Date: Sun, 22 Sep 2019 17:36:18 +0200 Subject: [PATCH] Additional fix for #2629 with API API object's notes fields now correctly preserve newlines. --- app/Api/V1/Requests/AccountUpdateRequest.php | 2 +- app/Api/V1/Requests/AttachmentStoreRequest.php | 2 +- app/Api/V1/Requests/AttachmentUpdateRequest.php | 2 +- app/Api/V1/Requests/BillRequest.php | 2 +- app/Api/V1/Requests/PiggyBankRequest.php | 2 +- app/Api/V1/Requests/RecurrenceUpdateRequest.php | 2 +- app/Api/V1/Requests/Request.php | 2 +- app/Api/V1/Requests/TransactionLinkRequest.php | 2 +- app/Api/V1/Requests/TransactionStoreRequest.php | 2 +- app/Http/Requests/Request.php | 15 +++++++++++++++ 10 files changed, 24 insertions(+), 9 deletions(-) diff --git a/app/Api/V1/Requests/AccountUpdateRequest.php b/app/Api/V1/Requests/AccountUpdateRequest.php index 36e974b77c..81777c5af2 100644 --- a/app/Api/V1/Requests/AccountUpdateRequest.php +++ b/app/Api/V1/Requests/AccountUpdateRequest.php @@ -76,7 +76,7 @@ class AccountUpdateRequest extends Request 'opening_balance_date' => $this->date('opening_balance_date'), 'cc_type' => $this->nullableString('credit_card_type'), 'cc_Monthly_payment_date' => $this->nullableString('monthly_payment_date'), - 'notes' => $this->nullableString('notes'), + 'notes' => $this->nullableNlString('notes'), 'interest' => $this->nullableString('interest'), 'interest_period' => $this->nullableString('interest_period'), ]; diff --git a/app/Api/V1/Requests/AttachmentStoreRequest.php b/app/Api/V1/Requests/AttachmentStoreRequest.php index 63047134f2..464319a3ad 100644 --- a/app/Api/V1/Requests/AttachmentStoreRequest.php +++ b/app/Api/V1/Requests/AttachmentStoreRequest.php @@ -56,7 +56,7 @@ class AttachmentStoreRequest extends Request return [ 'filename' => $this->string('filename'), 'title' => $this->string('title'), - 'notes' => $this->string('notes'), + 'notes' => $this->nlString('notes'), 'model' => $this->string('model'), 'model_id' => $this->integer('model_id'), ]; diff --git a/app/Api/V1/Requests/AttachmentUpdateRequest.php b/app/Api/V1/Requests/AttachmentUpdateRequest.php index 0bc823b402..f3e148f0f0 100644 --- a/app/Api/V1/Requests/AttachmentUpdateRequest.php +++ b/app/Api/V1/Requests/AttachmentUpdateRequest.php @@ -51,7 +51,7 @@ class AttachmentUpdateRequest extends Request return [ 'filename' => $this->string('filename'), 'title' => $this->string('title'), - 'notes' => $this->string('notes'), + 'notes' => $this->nlString('notes'), 'model' => $this->string('model'), 'model_id' => $this->integer('model_id'), ]; diff --git a/app/Api/V1/Requests/BillRequest.php b/app/Api/V1/Requests/BillRequest.php index dba2b93e7b..c2da7be3e6 100644 --- a/app/Api/V1/Requests/BillRequest.php +++ b/app/Api/V1/Requests/BillRequest.php @@ -70,7 +70,7 @@ class BillRequest extends Request 'repeat_freq' => $this->string('repeat_freq'), 'skip' => $this->integer('skip'), 'active' => $active, - 'notes' => $this->string('notes'), + 'notes' => $this->nlString('notes'), ]; return $data; diff --git a/app/Api/V1/Requests/PiggyBankRequest.php b/app/Api/V1/Requests/PiggyBankRequest.php index 7fad9502e8..cff1691703 100644 --- a/app/Api/V1/Requests/PiggyBankRequest.php +++ b/app/Api/V1/Requests/PiggyBankRequest.php @@ -62,7 +62,7 @@ class PiggyBankRequest extends Request 'current_amount' => $this->string('current_amount'), 'startdate' => $this->date('start_date'), 'targetdate' => $this->date('target_date'), - 'notes' => $this->string('notes'), + 'notes' => $this->nlString('notes'), ]; } diff --git a/app/Api/V1/Requests/RecurrenceUpdateRequest.php b/app/Api/V1/Requests/RecurrenceUpdateRequest.php index dbf71745b9..ecefab906c 100644 --- a/app/Api/V1/Requests/RecurrenceUpdateRequest.php +++ b/app/Api/V1/Requests/RecurrenceUpdateRequest.php @@ -69,7 +69,7 @@ class RecurrenceUpdateRequest extends Request 'title' => $this->nullableString('title'), 'description' => $this->nullableString('description'), 'first_date' => $this->date('first_date'), - 'notes' => $this->nullableString('notes'), + 'notes' => $this->nullableNlString('notes'), 'repeat_until' => $this->date('repeat_until'), 'nr_of_repetitions' => $this->nullableInteger('nr_of_repetitions'), 'apply_rules' => $applyRules, diff --git a/app/Api/V1/Requests/Request.php b/app/Api/V1/Requests/Request.php index 45e85a5553..3312b7eed5 100644 --- a/app/Api/V1/Requests/Request.php +++ b/app/Api/V1/Requests/Request.php @@ -65,7 +65,7 @@ class Request extends FireflyIIIRequest 'opening_balance_date' => $this->date('opening_balance_date'), 'cc_type' => $this->string('credit_card_type'), 'cc_Monthly_payment_date' => $this->string('monthly_payment_date'), - 'notes' => $this->string('notes'), + 'notes' => $this->nlString('notes'), 'interest' => $this->string('interest'), 'interest_period' => $this->string('interest_period'), ]; diff --git a/app/Api/V1/Requests/TransactionLinkRequest.php b/app/Api/V1/Requests/TransactionLinkRequest.php index a5d37e70ea..02f1cbe91b 100644 --- a/app/Api/V1/Requests/TransactionLinkRequest.php +++ b/app/Api/V1/Requests/TransactionLinkRequest.php @@ -57,7 +57,7 @@ class TransactionLinkRequest extends Request 'link_type_name' => $this->string('link_type_name'), 'inward_id' => $this->integer('inward_id'), 'outward_id' => $this->integer('outward_id'), - 'notes' => $this->string('notes'), + 'notes' => $this->nlString('notes'), ]; } diff --git a/app/Api/V1/Requests/TransactionStoreRequest.php b/app/Api/V1/Requests/TransactionStoreRequest.php index 97dc307a20..69954ff8f1 100644 --- a/app/Api/V1/Requests/TransactionStoreRequest.php +++ b/app/Api/V1/Requests/TransactionStoreRequest.php @@ -242,7 +242,7 @@ class TransactionStoreRequest extends Request // some other interesting properties 'reconciled' => $this->convertBoolean((string)$object['reconciled']), - 'notes' => $this->stringFromValue($object['notes']), + 'notes' => $this->nlStringFromValue($object['notes']), 'tags' => $this->arrayFromValue($object['tags']), // all custom fields: diff --git a/app/Http/Requests/Request.php b/app/Http/Requests/Request.php index c95ff77255..627e3b1e3c 100644 --- a/app/Http/Requests/Request.php +++ b/app/Http/Requests/Request.php @@ -237,6 +237,21 @@ class Request extends FormRequest } + /** + * Return string value, but keep newlines, or NULL if empty. + * + * @param string $field + * + * @return string + */ + public function nullableNlString(string $field): string + { + if (!$this->has($field)) { + return null; + } + return app('steam')->nlCleanString((string)($this->get($field) ?? '')); + } + /** * Parse and clean a string. *