Fix percent-encoding string generation

Obey the RFC: only unreserved characters are left as is, all others are
percent-encoded.