{"record":{"id":"9d250855fd300eb6","repo":"Intervention/image","slug":"invalid-hsv-or-hsb-color-syntax-input","errorCode":null,"errorMessage":"Invalid hsv() or hsb() color syntax \"{input}\"","messagePattern":"Invalid hsv\\(\\) or hsb\\(\\) color syntax \"(.+?)\"","errorType":"exception","errorClass":"Intervention\\Image\\Exceptions\\InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/Colors/Hsv/Decoders/StringColorDecoder.php","lineNumber":53,"sourceCode":"            return false;\n        }\n\n        if (preg_match('/^hs(v|b)/i', $input) !== 1) {\n            return false;\n        }\n\n        return true;\n    }\n\n    /**\n     * Decode hsv/hsb 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 hsv() or hsb() color syntax \"' . $input . '\"');\n        }\n\n        $values = array_map(fn(string $value): int => match (strpos($value, '%')) {\n            false => intval(trim($value)),\n            default => intval(trim(str_replace('%', '', $value))),\n        }, [$matches['h'], $matches['s'], $matches['v']]);\n\n        // alpha value\n        if (array_key_exists('a', $matches)) {\n            $values[] = match (strpos($matches['a'], '%')) {\n                false => floatval(trim($matches['a'])),\n                default => floatval(trim(str_replace('%', '', $matches['a']))) / 100,\n            };\n        }\n\n        return new Color(...$values);\n    }\n}","sourceCodeStart":35,"sourceCodeEnd":71,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/Colors/Hsv/Decoders/StringColorDecoder.php#L35-L71","documentation":"The HSV/HSB string decoder received a string that starts with 'hsv' or 'hsb' but does not match the single supported syntax: hsv(H S V) or hsb(H, S, V) where hue is a plain number (optional 'deg'), saturation and value are numbers with optional '%', and an optional alpha ('/ 0.5', ', 50%', ' 0.5') may follow (PATTERN in src/Colors/Hsv/Decoders/StringColorDecoder.php:18-25). Anything else fails the regex and throws InvalidArgumentException.","triggerScenarios":"Passing strings like 'hsv(120; 50%; 50%)' (semicolon separator), 'hsv(-10, 50%, 50%)' (negative hue), 'hsv(none, 0%, 0%)' (CSS 'none' keyword), 'hsv(120, 50%)' (missing value), or 'hsv(120, 50%, 50%, )' (trailing comma) to Hsv\\Color::parse(), a manager color input, or fill()/backgroundColor() options.","commonSituations":"CSS color strings copied from design tools or CSS4 specs that use syntax variants the library does not support; user input not sanitized before being handed to the color parser; separators or units assumed more permissive than they are.","solutions":["Rewrite the string to the supported format: comma or single-space separated, e.g. 'hsv(120, 50%, 50%)' or 'hsv(120deg 50% 50% / 0.5)'","Remove unsupported tokens: 'none', negative numbers, extra units","If the input is dynamic, pre-validate with a regex mirroring the supported syntax before handing it to the library","For programmatic values, build the color directly with Hsv\\Color::create(h, s, v, alpha) instead of parsing a string"],"exampleFix":"// before\n$color = Hsv\\Color::parse('hsv(120; 50%; 50%)'); // Invalid hsv() or hsb() color syntax\n\n// after\n$color = Hsv\\Color::parse('hsv(120, 50%, 50%)');\n// or without string parsing:\n$color = Hsv\\Color::create(120, 50, 50);","handlingStrategy":"validation","validationCode":"$ok = is_string($input)\n    && (bool) preg_match('/^hs(v|b) ?\\( ?[0-9.]+(?:deg)?([, ])[0-9.]+%?\\\\1[0-9.]+%?(?: ?\\/ ?|[, ])(?:0?\\\\.[0-9]+|[0-9]{1,3}%|1|0)? ?\\)$/i', $input);\n// or simply wrap the risky parse and inspect the message","typeGuard":"function isHsvString(mixed $input): bool\n{\n    return is_string($input) && (bool) preg_match('/^hs(v|b) ?\\(/i', $input);\n}","tryCatchPattern":"try {\n    $color = Hsv\\Color::parse($input);\n} catch (Intervention\\Image\\Exceptions\\InvalidArgumentException $e) {\n    // normalize $input (e.g. fix separators) and retry, or reject the input\n}","preventionTips":["Normalize separators to a single comma or single space before parsing","Reject 'none', negative numbers, and unexpected units at the input boundary","Prefer Hsv\\Color::create() over string parsing for programmatic values"],"tags":["color","hsv","hsb","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"}