Skip to content

[Mentions] 3 characters hex color and isDark util: Unsupported operand types: string + string #3693

@Ornanovitch

Description

@Ornanovitch

Current Behavior

Mentioning a group which has been set up with a 3 characters hex color brings an error when you try to mention it: TypeError: Unsupported operand types: string + string in /var/www/flarum2.localhost/PATH_TO_MONOREPO/extensions/mentions/src/ConfigureMentions.php:208

Steps to Reproduce

  1. Set up a group with a 3 char hex color (e.g. #CCC)
  2. Mention this group in a conversation

Expected Behavior

The 3 char. hex color should be converted to a 6 char. hex color in order to being parsed in the isDark util

Screenshots

No response

Environment

  • Flarum version: main branch
  • local dev env

Output of php flarum info

No response

Possible Solution

The original javascript isDark util is working fine. This is the php implementation for Mentions which is in cause:

        $hexNumbers = Str::replace('#', '', $hexColor);
        if (Str::length($hexNumbers) === 3) {
            $hexNumbers += $hexNumbers;
        }

should be:

        $hexNumbers = Str::replace('#', '', $hexColor);
        if (Str::length($hexNumbers) === 3) {
            $hexNumbers = $hexNumbers . $hexNumbers;
        }

Additional Context

No response

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions