{"record":{"id":"989525f11a3a9075","repo":"Intervention/image","slug":"invalid-oklab-color-syntax-input","errorCode":null,"errorMessage":"Invalid oklab() color syntax \"{input}\"","messagePattern":"Invalid oklab\\(\\) color syntax \"(.+?)\"","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Colors/Oklab/Decoders/StringColorDecoder.php","lineNumber":56,"sourceCode":"            return false;\n        }\n\n        if (!str_starts_with(strtolower($input), 'oklab')) {\n            return false;\n        }\n\n        return true;\n    }\n\n    /**\n     * Decode hsl color strings.\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 oklab() color syntax \"' . $input . '\"');\n        }\n\n        $values = [\n            $this->decodeChannelValue($matches['l'], Lightness::class),\n            $this->decodeChannelValue($matches['a'], A::class),\n            $this->decodeChannelValue($matches['b'], B::class),\n        ];\n\n        // alpha value\n        if (array_key_exists('alpha', $matches)) {\n            $values[] = $this->decodeAlphaChannelValue($matches['alpha']);\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/Oklab/Decoders/StringColorDecoder.php#L38-L74","documentation":"A string starting with 'oklab' failed the decoder's strict regex (PATTERN in src/Colors/Oklab/Decoders/StringColorDecoder.php:21-28). Supported syntax: oklab(L A B) with comma or space separators, where L must be '0', '1', '0.xx' or a percentage like '50%', A and B must be decimal form (0, -0.4, 0.123) or percentages, and an optional alpha ('/ 0.5', ', 50%', ' 0.5') may follow.","triggerScenarios":"Examples that fail: 'oklab(50, 0.1, 0.1)' (integer lightness without %), 'oklab(0.5, -1, 0.1)' (negative integer a/b without %), 'oklab(0.5, 0.1)' (missing b), 'oklab(none 0.1 0.1)' (CSS 'none' keyword), 'oklab(0.5, 0.1, 0.1 / )' (empty alpha), or a missing closing parenthesis.","commonSituations":"Copying modern CSS oklab() syntax (which allows integers, 'none', 'deg' variants) and assuming the library accepts every CSS form; unvalidated user input in color pickers feeding the parser.","solutions":["Use the accepted forms: 'oklab(0.5, 0.1, 0.1)', 'oklab(50% 0.1 -0.05 / 0.5)'","Express integer lightness as a percentage ('50%') and negative integer axes as decimals ('-1' -> '-1%' or '-0.4')","Pre-validate user input with a regex mirroring the supported syntax","Build colors programmatically with Oklab\\Color::create(l, a, b, alpha) instead of parsing strings"],"exampleFix":"// before\n$color = Oklab\\Color::parse('oklab(50, 0.1, 0.1)'); // integer lightness rejected\n\n// after\n$color = Oklab\\Color::parse('oklab(50%, 0.1, 0.1)');\n// or construct directly:\n$color = Oklab\\Color::create(0.5, 0.1, 0.1);","handlingStrategy":"validation","validationCode":"$pattern = '/^oklab ?\\( ?(1|0|0?\\.[0-9]+|[0-9.]+%)([, ])(-?0|-?0?\\.[0-9.]+|-?[0-9.]+%)\\\\1(-?0|-?0?\\.[0-9.]+|-?[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    // reject or normalize (e.g. 'oklab(50, ...)' -> 'oklab(50%, ...)') before parse()\n}","typeGuard":"function looksLikeOklabString(mixed $input): bool\n{\n    return is_string($input) && str_starts_with(strtolower($input), 'oklab');\n}","tryCatchPattern":"try {\n    $color = Oklab\\Color::parse($input);\n} catch (Intervention\\Image\\Exceptions\\InvalidArgumentException $e) {\n    // reformat the string (percent lightness, decimal axes) and retry or reject\n}","preventionTips":["Emit lightness as percent or 0..1 decimal, never a bare integer","Write a/b axes as decimals (0.1, -0.05) or percentages","Round-trip your formatter through parse() in tests to catch syntax drift"],"tags":["color","oklab","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"}