Escape query, fix line endings