From 6fb7444fe4b8014682c1530033ddda02946dc996 Mon Sep 17 00:00:00 2001 From: Lars Holmberg Date: Sun, 12 May 2024 19:56:31 +0200 Subject: [PATCH] stop escaping errors for requests endpoint Fixes #2674, at least the most annoying part of it. --- locust/test/test_web.py | 11 +++++++++-- locust/web.py | 6 +----- 2 files changed, 10 insertions(+), 7 deletions(-) diff --git a/locust/test/test_web.py b/locust/test/test_web.py index d756b247ab..a9a0b6c1b8 100644 --- a/locust/test/test_web.py +++ b/locust/test/test_web.py @@ -183,10 +183,17 @@ def test_failure_stats_csv(self): self._check_csv_headers(response.headers, "failures") def test_request_stats_with_errors(self): - self.stats.log_error("GET", "/", Exception("Error1337")) + self.stats.log_error("GET", "/", Exception("Error with special characters {'foo':'bar'}")) response = requests.get("http://127.0.0.1:%i/stats/requests" % self.web_port) self.assertEqual(200, response.status_code) - self.assertIn("Error1337", response.text) + + # escaped, old school + # self.assertIn( + # '"Exception("Error with special characters{'foo':'bar'}")"', response.text + # ) + + # not html escaping, leave that to the frontend + self.assertIn("\"Exception(\\\"Error with special characters {'foo':'bar'}\\\")", response.text) def test_reset_stats(self): try: diff --git a/locust/web.py b/locust/web.py index dc219362c6..e596301cb0 100644 --- a/locust/web.py +++ b/locust/web.py @@ -395,11 +395,7 @@ def request_stats() -> Response: for s in chain(sort_stats(environment.runner.stats.entries), [environment.runner.stats.total]): stats.append(s.to_dict()) - for e in environment.runner.errors.values(): - err_dict = e.serialize() - err_dict["name"] = escape(err_dict["name"]) - err_dict["error"] = escape(err_dict["error"]) - errors.append(err_dict) + errors = [e.serialize() for e in environment.runner.errors.values()] # Truncate the total number of stats and errors displayed since a large number of rows will cause the app # to render extremely slowly. Aggregate stats should be preserved.