Fix crash when query part contains invalid chars