mirror of
https://github.com/firefly-iii/firefly-iii.git
synced 2025-02-25 18:45:27 -06:00
Fix bad array validation.
This commit is contained in:
parent
c910cbe5da
commit
08f347cd57
@ -275,6 +275,10 @@ class TransactionStoreRequest extends FormRequest
|
||||
{
|
||||
$validator->after(
|
||||
function (Validator $validator) {
|
||||
|
||||
// must be valid array.
|
||||
$this->validateTransactionArray($validator);
|
||||
|
||||
// must submit at least one transaction.
|
||||
$this->validateOneTransaction($validator);
|
||||
|
||||
|
@ -53,6 +53,9 @@ trait TransactionValidation
|
||||
* @var array $transaction
|
||||
*/
|
||||
foreach ($transactions as $index => $transaction) {
|
||||
if(!is_int($index)) {
|
||||
continue;
|
||||
}
|
||||
$this->validateSingleAccount($validator, $index, $transactionType, $transaction);
|
||||
}
|
||||
}
|
||||
@ -178,6 +181,20 @@ trait TransactionValidation
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* @param Validator $validator
|
||||
*/
|
||||
public function validateTransactionArray(Validator $validator): void {
|
||||
$transactions = $this->getTransactionsArray($validator);
|
||||
foreach($transactions as $key => $value) {
|
||||
if(!is_int($key)) {
|
||||
$validator->errors()->add('transactions.0.description', (string) trans('validation.at_least_one_transaction'));
|
||||
Log::debug('Added error: at_least_one_transaction.');
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds an error to the validator when there are no transactions in the array of data.
|
||||
*
|
||||
@ -235,8 +252,6 @@ trait TransactionValidation
|
||||
foreach ($transactions as $transaction) {
|
||||
$originalType = $this->getOriginalType((int) ($transaction['transaction_journal_id'] ?? 0));
|
||||
// if type is not set, fall back to the type of the journal, if one is given.
|
||||
|
||||
|
||||
$types[] = $transaction['type'] ?? $originalType;
|
||||
}
|
||||
$unique = array_unique($types);
|
||||
|
Loading…
Reference in New Issue
Block a user