TurboGears / TurboGears/backlash
__traceback_info__ containing a double quote corrupts the frame tooltip markup
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 13
- Forks
- 13
- PR merge metrics
- No merged PRs in 30d
Description
Goal
Escape __traceback_info__ for use inside an HTML attribute, so that a value
containing a double quote cannot corrupt the traceback summary markup.
Done when: a __traceback_info__ value containing " renders as readable text
in the frame tooltip instead of terminating the attribute, and a test covers it.
Reproduction (reproduces on Python 3.9 through 3.14):
from backlash.tbtools import get_current_traceback
def f():
__traceback_info__ = 'expected "quoted" value'
raise ValueError('boom')
try:
f()
except Exception:
tb = get_current_traceback()
print([l for l in tb.render_summary().splitlines() if 'title' in l][0])
Current output - the attribute ends at the first inner quote, and the remaining
text is parsed as further attributes, so the tooltip shows only expected:
<li title="expected "quoted" value"><div class="frame" id="frame-...">
Cause: backlash/tbtools.py renders ' title="%s"' % escape(frame.info), and
backlash.utils.escape only translates " when called with quote=True, which
this call site does not do. Escaping &, < and > is sufficient for element
text but not for an attribute value.
Suggested minimal fix: pass quote=True at that call site. Alternatively,
backlash.utils.escape could be replaced by html.escape from the standard
library, whose quote parameter defaults to True; that is a wider change
because the helper has other call sites.
Why
__traceback_info__ is the Paste-era convention for attaching context to a
frame, and the values developers attach are frequently quoted strings: a SQL
statement, a template name, a repr of a parameter dict. Any double quote in
that value truncates the tooltip, so the frame annotation is unreliable
precisely for the values it exists to display.
This is the only place in the codebase where escaped output is written into an
HTML attribute; every other interpolation (filename, current_line,
exception, title) targets element text, where the current escape default
is correct. So the fix is a single call site, not a broader audit.
Verified as pre-existing rather than a regression: the same reproduction fails
identically on the commit preceding the recent modernization work.
References
backlash/tbtools.py(Traceback.render_summary, theframe.infotitle
attribute;Frame.infois populated from__traceback_info__)backlash/utils.py(escape, note thequote=Falsedefault)tests/test_tbtools.pymay be a natural home for a regression test
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start in backlash/tbtools.py at Traceback.render_summary, where frame.info is used for the title attribute, and review backlash/utils.py to understand escape's quote handling. Add a regression test in tests/test_tbtools.py using a quoted traceback_info value. Done means the rendered tooltip preserves the quoted text and the test passes.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- devtools
- Issue type
- Bug
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Activity status
- Quiet
- Clarity
- Clearly specified
- Newbie friendliness
- 88/100