kovidgoyal/kitty · error

invalid data URI: no comma found

Error message

invalid data URI: no comma found

What it means

parse_data_uri was given a data: URI that contains no comma separating the header (MIME[;base64]) from the payload, so it cannot be decoded. It is hit when parsing a uri-list from a drop that contains a malformed data: URI.

Source

Thrown at kittens/dnd/drop.go:391

	path string // for file URIs: the local filesystem path (empty if not a valid file URI)
	mime string // for data URIs: the MIME type
	data []byte // for data URIs: the decoded payload
}

// ext_for_mime returns a file extension (with leading dot) for a MIME type.
func ext_for_mime(mime string) string {
	for _, x := range utils.GuessFileExtensions(mime) {
		return x
	}
	return ""
}

// parse_data_uri decodes a data: URI and returns the MIME type and raw data.
func parse_data_uri(uri string) (mime string, data []byte, err error) {
	rest := strings.TrimPrefix(uri, "data:")
	comma_idx := strings.Index(rest, ",")
	if comma_idx < 0 {
		err = fmt.Errorf("invalid data URI: no comma found")
		return
	}
	header := rest[:comma_idx]
	payload := rest[comma_idx+1:]

	is_base64 := strings.HasSuffix(header, ";base64")
	if is_base64 {
		header = header[:len(header)-7]
	}

	mime = strings.TrimSpace(header)
	if mime == "" {
		mime = "text/plain"
	}
	// Strip parameters (e.g. ;charset=UTF-8) so the MIME type is clean.
	mime, _, _ = strings.Cut(mime, ";")

	if is_base64 {

View on GitHub (pinned to 6d5d0c4406)

Solutions

  1. Fix the source data: URI to include a comma, e.g. 'data:text/plain;base64,SGVsbG8=' or 'data:,hello'
  2. Validate/sanitize URI lists before feeding them to the drop path
  3. Handle the error at the caller and skip the offending URI instead of aborting the whole drop

Example fix

// before
"data:text/plain"
// after
"data:text/plain,hello"
Defensive patterns

Strategy: validation

Validate before calling

func validDataURI(s string) bool {
	rest := strings.TrimPrefix(s, "data:")
	return strings.Contains(rest, ",")
}

Try / catch

Skip malformed entries and continue processing the rest of the uri-list rather than failing the whole drop.

Prevention

When it happens

Trigger: A dropped text/uri-list contains an entry like 'data:text/plain' with no ',' — parse_uri_list calls parse_data_uri which fails on strings.Index(rest, ",") < 0.

Common situations: A source application generated a truncated/malformed data: URI; user hand-crafted a URI list missing the comma; copy/paste truncation of long data URIs.

Related errors


AI-assisted analysis of kovidgoyal/kitty@6d5d0c4406 (2026-08-27). Data as JSON: /api/errors/cc0745deb2e83aa4. Report an issue: GitHub.