{"record":{"id":"aeb474424fbd20f9","repo":"Intervention/image","slug":"invalid-data-uri-scheme","errorCode":null,"errorMessage":"Invalid data uri scheme","messagePattern":"Invalid data uri scheme","errorType":"exception","errorClass":"InvalidArgumentException","httpStatus":null,"severity":"error","filePath":"src/DataUri.php","lineNumber":78,"sourceCode":"            mediaType: $mediaType,\n            parameters: $parameters,\n            base64: $base64,\n        );\n    }\n\n    /**\n     * {@inheritdoc}\n     *\n     * @see DataUriInterface::parse()\n     *\n     * @throws InvalidArgumentException\n     */\n    public static function parse(string|Stringable $dataUriScheme): self\n    {\n        $result = preg_match(self::PATTERN, (string) $dataUriScheme, $matches);\n\n        if ($result === false || $result === 0) {\n            throw new InvalidArgumentException('Invalid data uri scheme');\n        }\n\n        $isBase64Encoded = $matches['base64'] !== '';\n\n        $datauri = new self(\n            data: $isBase64Encoded ? base64_decode($matches['data'], strict: true) : rawurldecode($matches['data']),\n            mediaType: $matches['mediaType'],\n            base64: $isBase64Encoded,\n        );\n\n        if ($matches['parameters'] !== '') {\n            $parameters = explode(';', $matches['parameters']);\n            $parameters = array_filter($parameters, fn(string $value): bool => $value !== '');\n            $parameters = array_map(fn(string $value): array => explode('=', $value), $parameters);\n            foreach ($parameters as $parameter) {\n                $datauri->setParameter(...$parameter);\n            }\n        }","sourceCodeStart":60,"sourceCodeEnd":96,"githubUrl":"https://github.com/Intervention/image/blob/5598b9e39751c34afc5cdee84abef77f92c26f68/src/DataUri.php#L60-L96","documentation":"DataUri::parse() applies a strict regex for RFC 2397 data URIs: a 'data:' prefix, an optional mediaType, optional ;-separated parameters, an optional ';base64' marker, then a comma and the payload. Any string not matching that shape fails the regex and throws this InvalidArgumentException.","triggerScenarios":"Passing 'data:image/png;base64' (missing comma and payload), 'image/png;base64,...' (missing 'data:' prefix), a normal URL ('https://example.com/a.png'), or a media type containing characters outside [-+.\\w] such as spaces.","commonSituations":"Data URLs truncated by transport or copy-paste; frontends sending regular URLs where the backend expects a data URI; URL-encoded whitespace sneaking into the media type.","solutions":["Ensure the string is a complete data URI: data:[mediaType][;parameters][;base64],<data>","If the input is a URL, fetch its contents instead of parsing it as a data URI","Trim and URL-decode the incoming value before parsing"],"exampleFix":"// before\n$uri = DataUri::parse($request->input('avatar'));\n\n// after\n$value = trim((string) $request->input('avatar'));\n$uri = str_starts_with($value, 'data:')\n    ? DataUri::parse($value)\n    : DataUri::create(file_get_contents($value));","handlingStrategy":"validation","validationCode":"function isDataUri(string $value): bool\n{\n    return preg_match('#^data:[\\w/+.-]*(;[\\w-=]+)*(;base64)?,.+#', $value) === 1;\n}\n\nif (!isDataUri($candidate)) {\n    throw new \\RuntimeException('Expected a data URI');\n}","typeGuard":null,"tryCatchPattern":"try {\n    $uri = DataUri::parse($value);\n} catch (\\Intervention\\Image\\Exceptions\\InvalidArgumentException $e) {\n    // not a data URI - fetch instead if it is a URL, or reject the input\n}","preventionTips":["Check for the 'data:' prefix and a comma before parsing","Trim and URL-decode transport values first","Do not pass regular URLs to DataUri::parse()"],"tags":["data-uri","parsing","validation"],"backgroundTag":"invalid-data-uri","analyzedSha":"5598b9e39751c34afc5cdee84abef77f92c26f68","analyzedAt":"2026-08-23T02:17:31.068Z","schemaVersion":2},"datasetVersion":"2026-08-23T08:06:27.607Z"}