Percent-encode the text s (libtorrent escape_string). Everything except -_!.~*() and [A-Za-z0-9] is escaped.
The string is first converted to its UTF-8 bytes, then each byte is encoded, so non-ASCII characters round-trip correctly through unescape when its result is decoded back from UTF-8.