Not a bug copy & paste of image to make an attachment is blocked as webp isn't an allowed extension by default

Xon

Well-known member
Affected version
2.3.7
Webp should be an allowed attachment extension by default, so when image optimization is enabled attachment copy & paste doesn't break with a rather unfriendly error message (the actual image type isn't reported)
 
It is an allowed extension by default and it was added (if not already existing) in the 2.3.0 Alpha upgrade script.

JSON:
{
    "edit_format": "textbox",
    "edit_format_params": "rows=6",
    "data_type": "string",
    "sub_options": [],
    "validation_class": "",
    "validation_method": "",
    "advanced": false,
    "default_value": "zip\ntxt\npdf\npng\njpg\njpeg\njpe\ngif\nwebp",
    "relations": {
        "attachments": 40
    }
}

PHP:
    public function step7()
    {
        $db = $this->db();

        $attachmentExtensions = $db->fetchOne('
            SELECT option_value
            FROM xf_option
            WHERE option_id = \'attachmentExtensions\'
        ');

        $attachmentExtensions = preg_split('/\s+/', trim($attachmentExtensions), -1, PREG_SPLIT_NO_EMPTY);

        if (!in_array('webp', $attachmentExtensions))
        {
            $newAttachmentExtensions = $attachmentExtensions;
            $newAttachmentExtensions[] = 'webp';
            $newAttachmentExtensions = implode("\n", $newAttachmentExtensions);

            $this->executeUpgradeQuery('
                UPDATE xf_option
                SET option_value = ?
                WHERE option_id = \'attachmentExtensions\'
            ', $newAttachmentExtensions);
        }
    }
 
I was setting up an XF2.3.7 site and someone else changed the option to allow something and overwrote the default. Apologies!

But not allowing webp attachments when image optimization forces webp attachments is definitely on the confusing side
 
Back
Top Bottom