grpc-ecosystem/grpc-gateway · error

invalid percent-encoding in %q

Error message

invalid percent-encoding in %q

What it means

Lexical-validation error from expectPChars: the literal ended while a percent-encoding was mid-parse (state pct1/pct2), i.e. a trailing '%' or '%A' with fewer than two hex digits. The input string is reported so the truncated escape can be found.

Source

Thrown at internal/httprule/parse.go:328

		case '0' <= r && r <= '9':
			continue
		}
		switch r {
		case '-', '.', '_', '~':
			// unreserved
		case '!', '$', '&', '\'', '(', ')', '*', '+', ',', ';', '=':
			// sub-delims
		case ':', '@':
			// rest of pchar
		case '%':
			// pct-encoded
			st = pct1
		default:
			return fmt.Errorf("invalid character in path segment: %q(%U)", r, r)
		}
	}
	if st != init {
		return fmt.Errorf("invalid percent-encoding in %q", t)
	}
	return nil
}

// expectIdent determines if "ident" is a valid identifier in .proto schema ([[:alpha:]_][[:alphanum:]_]*).
func expectIdent(ident string) error {
	if ident == "" {
		return errors.New("empty identifier")
	}
	for pos, r := range ident {
		switch {
		case '0' <= r && r <= '9':
			if pos == 0 {
				return fmt.Errorf("identifier starting with digit: %s", ident)
			}
			continue
		case 'A' <= r && r <= 'Z':
			continue

View on GitHub (pinned to a58a4436a3)

Solutions

  1. Complete the percent-escape with exactly two hex digits, or remove the dangling '%'.
  2. Encode a literal percent as %25.
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at internal/httprule/parse.go:328 when the library encounters an invalid state.

Common situations: See trigger scenarios.


AI-assisted analysis of grpc-ecosystem/grpc-gateway@a58a4436a3 (2026-09-02). Data as JSON: /api/errors/691d4d177af86f2b. Report an issue: GitHub.