Directly pass filename
authorCyperghost <olaf_schmitz_1@t-online.de>
Thu, 31 Oct 2024 07:30:17 +0000 (08:30 +0100)
committerCyperghost <olaf_schmitz_1@t-online.de>
Thu, 31 Oct 2024 07:30:17 +0000 (08:30 +0100)
Use early continue
Fix file extension check

wcfsetup/install/files/lib/system/form/builder/field/UploadFormField.class.php
wcfsetup/install/lang/de.xml
wcfsetup/install/lang/en.xml

index bb60dc0e16d1de297e578c76c95ab2d1ab5a1680..13ed5a2ea37fc1434be15cbc63a82baf12a303ae 100644 (file)
@@ -319,24 +319,26 @@ class UploadFormField extends AbstractFormField
             });
 
             foreach ($this->getValue() as $file) {
-                if (!\in_array($file->getFilenameExtension(), $allowedFileExtensions)) {
-                    foreach ($specialFileExtensions as $extension) {
-                        if (\str_ends_with(".{$file->getFilename()}", $extension)) {
-                            continue 2;
-                        }
-                    }
+                if (\in_array($file->getFilenameExtension(), $allowedFileExtensions)) {
+                    continue;
+                }
 
-                    $this->addValidationError(
-                        new FormFieldValidationError(
-                            'acceptableFileExtensions',
-                            'wcf.form.field.upload.error.fileExtension',
-                            [
-                                'allowedFileExtensions' => $this->allowedFileExtensions,
-                                'file' => $file,
-                            ]
-                        )
-                    );
+                foreach ($specialFileExtensions as $extension) {
+                    if (\str_ends_with($file->getFilename(), ".{$extension}")) {
+                        continue 2;
+                    }
                 }
+
+                $this->addValidationError(
+                    new FormFieldValidationError(
+                        'acceptableFileExtensions',
+                        'wcf.form.field.upload.error.fileExtension',
+                        [
+                            'allowedFileExtensions' => $this->allowedFileExtensions,
+                            'filename' => $file->getFilename(),
+                        ]
+                    )
+                );
             }
         }
     }
index b38da4ad785ce6b286dd55b1ea915861a2b1caac..62793c611b2d0ef447b54b5fac2ac1de56bb82bb 100644 (file)
@@ -4100,7 +4100,7 @@ Dateianhänge:
                <item name="wcf.form.field.upload.error.maximumImageHeight"><![CDATA[Die Datei „{$file->getFilename()}“ darf maximal {#$maximumImageHeight} Pixel hoch sein.]]></item>
                <item name="wcf.form.field.upload.error.minimum"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Du musst{else}Sie müssen{/if} mindestens {if $minimum > 1}{#$minimum} Dateien{else}eine Datei{/if} hochladen.]]></item>
                <item name="wcf.form.field.upload.error.maximum"><![CDATA[{if LANGUAGE_USE_INFORMAL_VARIANT}Du darfst{else}Sie dürfen{/if} maximal {if $maximum > 1}{#$maximum} Dateien{else}eine Datei{/if} hochladen.]]></item>
-               <item name="wcf.form.field.upload.error.fileExtension"><![CDATA[Die Datei „{$file->getFilename()}“ hat eine ungültige Dateiendung. Erlaubt sind: {implode from=$allowedFileExtensions item=extension}{$extension}{/implode}.]]></item>
+               <item name="wcf.form.field.upload.error.fileExtension"><![CDATA[Die Datei „{$filename}“ hat eine ungültige Dateiendung. Erlaubt sind: {implode from=$allowedFileExtensions item=extension}{$extension}{/implode}.]]></item>
        </category>
        <category name="wcf.image">
                <item name="wcf.image.coverPhoto"><![CDATA[Titelbild]]></item>
index 5fab4999e3f2eb1eaa50d8706d5f74030b8226eb..e213f89ae24f3e8424d9473f5173c7328ff185ec 100644 (file)
@@ -4046,7 +4046,7 @@ Attachments:
                <item name="wcf.form.field.upload.error.maximumImageHeight"><![CDATA[The file “{$file->getFilename()}” may have a maximum height of {#$maximumImageHeight} pixels.]]></item>
                <item name="wcf.form.field.upload.error.minimum"><![CDATA[You must upload at least {if $minimum > 1}{#$minimum} files{else}one file{/if}.]]></item>
                <item name="wcf.form.field.upload.error.maximum"><![CDATA[You can upload a maximum of {if $maximum > 1}{#$maximum} files{else}one file{/if}.]]></item>
-               <item name="wcf.form.field.upload.error.fileExtension"><![CDATA[The file “{$file->getFilename()}” has an invalid file extension. Allowed are: {implode from=$allowedFileExtensions item=extension}{$extension}{/implode}.]]></item>
+               <item name="wcf.form.field.upload.error.fileExtension"><![CDATA[The file “{$filename}” has an invalid file extension. Allowed are: {implode from=$allowedFileExtensions item=extension}{$extension}{/implode}.]]></item>
        </category>
        <category name="wcf.image">
                <item name="wcf.image.coverPhoto"><![CDATA[Cover Photo]]></item>