{"record":{"id":"dddd0bdeedf99fe0","repo":"Intervention/image","slug":"invalid-oklch-color-syntax-input","errorCode":null,"errorMessage":"Invalid oklch() color syntax \"{input}\"","messagePattern":"Invalid oklch\\(\\) color syntax \"(.+?)\"","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Colors/Oklch/Decoders/StringColorDecoder.php","lineNumber":56,"sourceCode":"            return false;\n        }\n\n        if (!str_starts_with(strtolower($input), 'oklch')) {\n            return false;\n        }\n\n        return true;\n    }\n\n    /**\n     * Decode hsl color string.\n     *\n     * @throws InvalidArgumentException\n     */\n    public function decode(mixed $input): ColorInterface\n    {\n        if (preg_match(self::PATTERN, $input, $matches) !== 1) {\n            throw new InvalidArgumentException('Invalid oklch() color syntax \"' . $input . '\"');\n        }\n\n        $values = [\n            $this->decodeChannelValue($matches['l'], Lightness::class),\n            $this->decodeChannelValue($matches['c'], Chroma::class),\n            $this->decodeChannelValue($matches['h'], Hue::class),\n        ];\n\n        // alpha value\n        if (array_key_exists('a', $matches)) {\n            $values[] = $this->decodeAlphaChannelValue($matches['a']);\n        }\n\n        return new Color(...$values);\n    }\n\n    /**\n     * Decode channel value.","sourceCodeStart":38,"sourceCodeEnd":74,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Colors/Oklch/Decoders/StringColorDecoder.php#L38-L74","documentation":"A string starting with 'oklch' failed the decoder's regex (PATTERN in src/Colors/Oklch/Decoders/StringColorDecoder.php:21-28). Accepted syntax: oklch(L C H) with comma or space separators, L as '0', '1', '0.xx' or percent, C as decimal or percent, H as a plain number (0..360) with no unit, plus optional alpha ('/ 0.5', ', 50%', ' 0.5').","triggerScenarios":"Failing examples: 'oklch(0.5, 0.1, 150deg)' (hue unit not supported), 'oklch(70, 0.1, 150)' (integer lightness without %), 'oklch(0.5, -1, 150)' (negative integer chroma without %), 'oklch(none 0.1 150)' ('none' keyword), missing closing parenthesis, or a missing channel.","commonSituations":"Pasting modern CSS oklch() notation (which permits 'deg' on hue, 'none', integer lightness) and assuming full CSS compatibility; feeding unvalidated picker input to the parser.","solutions":["Write hue without a unit: 'oklch(0.5, 0.1, 150)'","Express integer lightness as percent ('70%') and negative chroma as decimal or percent","Pre-validate external strings against the supported syntax before parsing","Construct programmatically with Oklch\\Color::create(l, c, h, alpha) when no string is needed"],"exampleFix":"// before\n$color = Oklch\\Color::parse('oklch(0.5, 0.1, 150deg)'); // hue unit rejected\n\n// after\n$color = Oklch\\Color::parse('oklch(0.5, 0.1, 150)');\n// or construct directly:\n$color = Oklch\\Color::create(0.5, 0.1, 150);","handlingStrategy":"validation","validationCode":"$pattern = '/^oklch ?\\( ?(1|0|0?\\.[0-9]+|[0-9.]+%)([, ])(-?0|-?0?\\.[0-9.]+|-?[0-9.]+%)\\\\1[0-9.]+(?: ?\\/ ?|[, ] ?)?((?:0\\.[0-9]+)|1\\.0|\\.[0-9]+|[0-9]{1,3}%|1|0)? ?\\)$/i';\nif (!is_string($input) || preg_match($pattern, $input) !== 1) {\n    // strip 'deg' from hue, convert integer lightness to %, then retry parse()\n}","typeGuard":"function looksLikeOklchString(mixed $input): bool\n{\n    return is_string($input) && str_starts_with(strtolower($input), 'oklch');\n}","tryCatchPattern":"try {\n    $color = Oklch\\Color::parse($input);\n} catch (Intervention\\Image\\Exceptions\\InvalidArgumentException $e) {\n    // normalize input (hue without unit, lightness as %) and retry or reject\n}","preventionTips":["Never emit a unit on the oklch hue channel","Write lightness as percent or 0..1 decimal","Cover the string format in tests when you generate oklch() strings yourself"],"tags":["color","oklch","string-parsing","regex","css-color","php"],"backgroundTag":"css-color-parse-error","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}