fix: use %s placeholders in HTTPError to prevent Tornado from doubling % in gateway URLs#1620
Merged
krassowski merged 2 commits intoApr 30, 2026
Conversation
…g % in gateway URLs Tornado's HTTPError escapes '%' as '%%' in the log_message string when no positional args are provided. This caused gateway URLs containing percent- encoded characters (e.g. 'http%3A%2F%2F') to appear doubled in error responses and logs. Replace f-string log_message arguments in the three web.HTTPError raises in send_request_to_gateway() with '%s' placeholder strings and pass URL/message values through the args parameter. Tornado only escapes log_message when args is empty, so URL percent characters are preserved correctly. Add test_gateway_httperror_percent_not_doubled() to demonstrate the old f-string path doubles '%' and the new placeholder+args path does not. Closes jupyter-server#1503
|
+1, this issue is also affecting me. FYI, this was also fixed recently in a newer version of Tornado (6.5.0+), with a new get_message method, but the original log_message method and behavior is unchanged for backwards compatibility: |
ptch314
approved these changes
Apr 29, 2026
ptch314
left a comment
There was a problem hiding this comment.
LGTM. Note that this PR adds regression tests for when %s are correctly left alone. But we do not need test cases for the original behavior when %s are replaced with %%s, because Jupyter Server does not intentionally utilize this behavior of log_message anywhere.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
Closes #1503.
When the Gateway server is unreachable or returns an error, send_request_to_gateway() raises web.HTTPError passing the error message as an f-string. Tornado's HTTPError.init escapes % → %% in log_message when no positional args are provided. This caused URLs containing percent-encoded characters (e.g. http://host/?redirect=http%3A%2F%2Fexample.com) to appear with doubled percent signs in error responses and logs.
From Tornado's source:
\\python
if log_message and not args:
self.log_message = log_message.replace('%', '%%')
\\
Fix
Replace the three f-string log_message arguments in send_request_to_gateway() with %s format strings and pass URLs / messages as positional �rgs. When �rgs is non-empty Tornado skips the escaping, so percent-encoded characters in gateway URLs are preserved correctly.
Changes
Test
\
29 passed in 5.10s
\\