diff --git a/CHANGELOG.md b/CHANGELOG.md index 7c88629..e9ab078 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,3 +1,12 @@ +# v7.2.2 +## 12/13/2023 + +1. [](#improved) + * Add _inline errors_ for `file` field. Useful in combination with `form: no-validate: true` form setting. + * Validate filename against `uploads_dangerous_extensions` when using the `save:` action +1. [](#bugfix) + * Cleared 'basic captcha' value when invalid + # v7.2.1 ## 06/27/2023 diff --git a/blueprints.yaml b/blueprints.yaml index 4a7ec33..3c33671 100644 --- a/blueprints.yaml +++ b/blueprints.yaml @@ -1,7 +1,7 @@ name: Form slug: form type: plugin -version: 7.2.1 +version: 7.2.2 description: Enables forms handling and processing icon: check-square author: diff --git a/form.php b/form.php index 02eae7a..8355a03 100644 --- a/form.php +++ b/form.php @@ -518,7 +518,7 @@ public function onFormProcessed(Event $event): void $captcha_value = trim($form->value('basic-captcha')); if (!$captcha->validateCaptcha($captcha_value)) { $message = $params['message'] ?? $this->grav['language']->translate('PLUGIN_FORM.ERROR_BASIC_CAPTCHA'); - + $form->setData('basic-captcha', ''); $this->grav->fireEvent('onFormValidationError', new Event([ 'form' => $form, 'message' => $message @@ -667,6 +667,11 @@ public function onFormProcessed(Event $event): void $filename = $prefix . $this->udate($format, $raw_format) . $postfix . $ext; } + // Handle bad filenames. + if (!Utils::checkFilename($filename)) { + throw new RuntimeException(sprintf('Form save: File with extension not allowed: %s', $filename)); + } + /** @var Twig $twig */ $twig = $this->grav['twig']; $vars = [ diff --git a/templates/forms/fields/file/file.html.twig b/templates/forms/fields/file/file.html.twig index 96ac87e..a4b9d47 100644 --- a/templates/forms/fields/file/file.html.twig +++ b/templates/forms/fields/file/file.html.twig @@ -89,7 +89,14 @@ {{ macro.preview(path, file, _context) }} {% endfor %} {% include 'forms/fields/hidden/hidden.html.twig' with {field: {name: '_json.' ~ field.name}, value: (value ?? [])|json_encode } %} + + + {% if inline_errors and errors %} +