Escape query strings

Fixes #324