fix: use percent-placeholder args in HTTPError to prevent Tornado from doubling percent signs in gateway URLs - #1642
Merged
Carreau merged 1 commit intoMay 28, 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
Carreau
reviewed
May 28, 2026
Contributor
There was a problem hiding this comment.
I this usually the '%s' is a code small that one should use %r instead but it's pure improvement
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
Tornado's
web.HTTPErrorescapes%as%%in thelog_messagestring when no positional args are provided. This is by design — Tornado passeslog_message % argsthrough Python's%-formatting, so any literal%in the message must be doubled to survive.The three
HTTPErrorraises insend_request_to_gateway()used f-strings aslog_messagewith no args. When the gateway URL contains percent-encoded characters likehttp%3A%2F%2F, Tornado's escaping doubled every%:Closes #1503.
Fix
Replace f-string
log_messagearguments with%splaceholder strings and pass the URL/message values through theargsparameter. Tornado only escapeslog_messagewhenargsis empty, so URL percent characters are preserved correctly:Applied to all three
HTTPErrorraises ingateway_request().Test
Added
test_gateway_httperror_percent_not_doubled()that:HTTPErrorthe old way (f-string, no args) and asserts Tornado does double%— proves the old code was buggy.HTTPErrorthe new way (%splaceholder + args) and asserts%%is not present inlog_messageand the URL is intact inargs.