Skip to content

[BUG?] Unknown colors are replaced to BLACK silently. #819

@LanderlYoung

Description

@LanderlYoung

For vector.xml

<vector ...>
    <path
        android:fillColor="@android:color/white"
        android:pathData=""/>
</vector>

Note the android:fillColor="@android:color/white" part, this color is not supported by this tool, but replaced with Color.Black in the generated code without any error or warning.

The generated kotlin code is:

val ImIcBatchSelectUnchecked: ImageVector
    get() {
            ...
            path(fill = SolidColor(Color.Black)) { // <=== note here
            ...
    }

The hex color parse logic is in HexParser:

    fun toColorInt(value: String): Int {
        val hex = value.removePrefix("#").removePrefix("0x")

        val normalizedHex = if (hexRegex.matches(hex)) {
            when (hex.length) {
                3 -> "FF${expandShorthandHex(hex)}"
                6 -> "FF$hex"
                8 -> hex
                else -> DEFAULT_COLOR
            }
        } else {
            DEFAULT_COLOR
        }

        return normalizedHex.toUInt(16).toInt()
    }

Should we throw an exception instead of returning DEFAULT_COLOR, which is FF000000.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No fields configured for Enhancement.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions