Skip to content

Commit

Permalink
stop escaping errors for requests endpoint
Browse files Browse the repository at this point in the history
Fixes #2674, at least the most annoying part of it.
  • Loading branch information
cyberw committed May 12, 2024
1 parent 8fd6901 commit 6fb7444
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 7 deletions.
11 changes: 9 additions & 2 deletions locust/test/test_web.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
6 changes: 1 addition & 5 deletions locust/web.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down

0 comments on commit 6fb7444

Please sign in to comment.