process_uri: only encode if invalid