{"record":{"id":"217d43762a62965f","repo":"DenverCoder1/github-readme-streak-stats","slug":"invalid-color-color","errorCode":null,"errorMessage":"Invalid color: \" . $color","messagePattern":"Invalid color: \" \\. \\$color","errorType":"exception","errorClass":"AssertionError","httpStatus":500,"severity":"error","filePath":"src/card.php","lineNumber":730,"sourceCode":"        $color = \"{$chars[0]}{$chars[0]}{$chars[1]}{$chars[1]}{$chars[2]}{$chars[2]}\";\n    } elseif (strlen($color) === 4) {\n        $chars = str_split($color);\n        $color = \"{$chars[0]}{$chars[0]}{$chars[1]}{$chars[1]}{$chars[2]}{$chars[2]}{$chars[3]}{$chars[3]}\";\n    }\n\n    // convert to 6 digit hex and opacity\n    if (strlen($color) === 6) {\n        return [\n            \"color\" => \"#{$color}\",\n            \"opacity\" => 1,\n        ];\n    } elseif (strlen($color) === 8) {\n        return [\n            \"color\" => \"#\" . substr($color, 0, 6),\n            \"opacity\" => hexdec(substr($color, 6, 2)) / 255,\n        ];\n    }\n    throw new AssertionError(\"Invalid color: \" . $color);\n}\n\n/**\n * Convert transparent hex colors (4/8 digits) in an SVG to hex 6 digits and corresponding opacity attribute (0-1)\n *\n * @param string $svg The SVG for the card as a string\n * @return string The SVG with converted colors\n */\nfunction convertHexColors(string $svg): string\n{\n    // convert \"transparent\" to \"#0000\"\n    $svg = preg_replace(\"/(fill|stroke)=['\\\"]transparent['\\\"]/m\", '\\1=\"#0000\"', $svg);\n\n    // convert hex colors to 6 digits and corresponding opacity attribute\n    $svg = preg_replace_callback(\n        \"/(fill|stroke|stop-color)=['\\\"]#([0-9a-fA-F]{4}|[0-9a-fA-F]{8})['\\\"]/m\",\n        function ($matches) {\n            $attribute = $matches[1];","sourceCodeStart":712,"sourceCodeEnd":748,"githubUrl":"https://github.com/DenverCoder1/github-readme-streak-stats/blob/70dd50f921097927dc8314ac33a04b010a09924d/src/card.php#L712-L748","documentation":"convertHexColor() accepts 3/4/6/8-digit hex color strings and throws AssertionError for anything else. This library throws it when a color value passed into the SVG color-conversion pipeline is not valid hex notation.","triggerScenarios":"Passing a named CSS color (e.g. 'red'), an 'rgb(...)' string, a color missing the '#' prefix, an empty string, or a hex string of any length other than 3, 4, 6, or 8 into convertHexColors/convertHexColor.","commonSituations":"Users supplying custom theme colors via query parameters or config that aren't hex; copying colors from design tools that output rgb() or hsl() notation; truncating a hex string by mistake.","solutions":["Convert the input color to 6-digit hex format (e.g. '#ff0000') before passing it in","Ensure the color is a plain hex string without '#' being stripped by URL encoding","Add pre-validation that matches /^[0-9a-fA-F]{3,4}$|^[0-9a-fA-F]{6}$|^[0-9a-fA-F]{8}$/","If using named colors, map them to hex first"],"exampleFix":"// before\nconvertHexColor(\"red\");\n// after\nconvertHexColor(\"#ff0000\");","handlingStrategy":"validation","validationCode":"if (!preg_match('/^(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/', $color)) { throw new InvalidArgumentException(\"Not a hex color: $color\"); }","typeGuard":"function isHexColor(?string $c): bool { return $c !== null && preg_match('/^(?:[0-9a-fA-F]{3,4}|[0-9a-fA-F]{6}|[0-9a-fA-F]{8})$/', $c) === 1; }","tryCatchPattern":null,"preventionTips":["Normalize user-supplied colors to 6-digit hex before passing in","Use a color utility to convert named/rgb() colors to hex","Add unit tests for all color formats your app accepts"],"tags":["php","color-parsing","hex-color","validation"],"backgroundTag":"invalid-argument-format","analyzedSha":"70dd50f921097927dc8314ac33a04b010a09924d","analyzedAt":"2026-09-15T02:40:51.909Z","contentChangedAt":"2026-09-15T02:40:51.909Z","schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}