wesnoth / wesnoth

An open source, turn-based strategy game with a high fantasy theme.
https://www.wesnoth.org/
GNU General Public License v2.0
5.31k stars 995 forks source link

Improve hex color validation #9030

Closed soliton- closed 4 days ago

soliton- commented 4 days ago

Describe the desired feature

Currently the code just checks the length but not that the string is actually just hex characters.

https://github.com/wesnoth/wesnoth/blob/e67a91caf22429c56cd2012e324cd8ee212b5481/src/color.cpp#L64-L66

So for example foobar is not a valid hex color but shows no error.

As a test one can use:

[unit_type]
    [base_unit]
        id=Necromancer
    [/base_unit]
    id=Necromancer Recolor
    name=_"Necromancer Recolor"
    image="units/undead-necromancers/necromancer.png~PAL(E3DCDC, c9C3BE,999188,6E675C,514A3F,889880,506858,283028 > C1C1C1,919191,646464,444444,080808,7C999B,4C546C,262C31)"
[/unit_type]

which creates a new unit type based on the Necromancer with changed hair color.