]> git.ipfire.org Git - thirdparty/tornado.git/commitdiff
Format HTTPError.log_message only if args provided
authorHarsh Parekh <harsh_parekh@outlook.com>
Thu, 27 Feb 2025 16:45:44 +0000 (11:45 -0500)
committerHarsh Parekh <harsh_parekh@outlook.com>
Thu, 27 Feb 2025 18:18:22 +0000 (13:18 -0500)
Attempts to fix the [jupyter_server/issues/1503](https://github.com/jupyter-server/jupyter_server/issues/1503) issue

tornado/web.py

index 357c5f1aefd147bd89ddc7be519890faa7ab4899..3003fd8e07a3c113fe38d3a43ec7197b2731b539 100644 (file)
@@ -2520,8 +2520,6 @@ class HTTPError(Exception):
         self.log_message = log_message
         self.args = args
         self.reason = kwargs.get("reason", None)
-        if log_message and not args:
-            self.log_message = log_message.replace("%", "%%")
 
     def __str__(self) -> str:
         message = "HTTP %d: %s" % (
@@ -2529,7 +2527,8 @@ class HTTPError(Exception):
             self.reason or httputil.responses.get(self.status_code, "Unknown"),
         )
         if self.log_message:
-            return message + " (" + (self.log_message % self.args) + ")"
+            log_message = (self.log_message % self.args) if self.args else self.log_message
+            return message + " (" + log_message + ")"
         else:
             return message