Fix escaping issue in middleware.