From a455ffcce18d346cc4f77a9d51ebfe432eb40e38 Mon Sep 17 00:00:00 2001 From: Takeshi KOMIYA Date: Sun, 24 Sep 2017 13:52:59 +0900 Subject: [PATCH] Fix #4070: crashes when the warning message contains format strings --- CHANGES | 1 + sphinx/util/logging.py | 5 +++-- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/CHANGES b/CHANGES index ab05011d8..9119dc18c 100644 --- a/CHANGES +++ b/CHANGES @@ -34,6 +34,7 @@ Bugs fixed * #4049: Fix typo in output of sphinx-build -h * #4062: hashlib.sha1() must take bytes, not unicode on Python 3 * Avoid indent after index entries in latex (refs: #4066) +* #4070: crashes when the warning message contains format strings Testing diff --git a/sphinx/util/logging.py b/sphinx/util/logging.py index 04cb5fcab..2cdac6c40 100644 --- a/sphinx/util/logging.py +++ b/sphinx/util/logging.py @@ -356,10 +356,11 @@ class WarningIsErrorFilter(logging.Filter): return True elif self.app.warningiserror: location = getattr(record, 'location', '') + message = record.msg.replace('%', '%%') if location: - raise SphinxWarning(location + ":" + record.msg % record.args) + raise SphinxWarning(location + ":" + message % record.args) else: - raise SphinxWarning(record.msg % record.args) + raise SphinxWarning(message % record.args) else: return True