Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix debug_info logic to avoid ValueError on empty _debug_info #835

Closed
wants to merge 74 commits into from

Conversation

captainmalloc
Copy link
Contributor

In some situations the Template '_debug_info' can be empty. This causes the real exception to be masked by a new ValueError exeception:

  File "/usr/local/lib/python2.7/site-packages/jinja2/environment.py", line 1045, in generate
    yield self.environment.handle_exception(exc_info, True)
  File "/usr/local/lib/python2.7/site-packages/jinja2/environment.py", line 774, in handle_exception
    traceback = _make_traceback(exc_info, source_hint)
  File "/usr/local/lib/python2.7/site-packages/jinja2/debug.py", line 140, in make_traceback
    return translate_exception(exc_info, initial_skip)
  File "/usr/local/lib/python2.7/site-packages/jinja2/debug.py", line 182, in translate_exception
    lineno = template.get_corresponding_lineno(tb.tb_lineno)
  File "/usr/local/lib/python2.7/site-packages/jinja2/environment.py", line 1112, in get_corresponding_lineno
    for template_line, code_line in reversed(self.debug_info):
  File "/usr/local/lib/python2.7/site-packages/jinja2/environment.py", line 1128, in debug_info
    self._debug_info.split('&')]
ValueError: invalid literal for int() with base 10: ''

This bug fix simply check if '_debug_info' is not empty before working on it.

davidism and others added 27 commits November 8, 2017 12:02
Most non-user facing.
Fix typo instanciable > instantiable
Allow to pass a list to native_concat
In Python, it's legal to use splats in function calls like this:

  call_function('123', *b, c=5, **d)

Prior to this change, jinja2 did not allow that. It mandated that all
splatting had to take place at the end of the call:

  call_function('123', c=5, *b, **d)

This commit allows both orders.

Additionally, this commit adds tests for more things that are illegal:
namely giving a function a positional argument after using a splat to
unpack positional arguments or giving a function a named argument after
using a double splat to unpack keyword arguments.
fix unrelated docs issue
Found via `codespell -q 3` using v1.12.0.dev0
Fix typo: apparenlty -> apparently.
This unescapes after concatenating, to fix a bug introduced in Jinja
2.10 where lines concatenated contain escaped versions of non-ascii
characters.
The previous commit assumes that the filter will always be a Markup
type, which is not correct.
This ensures that we only concatenate Markup instances to other Markup
instances.
Fix escaped characters in indent filter
This is unmaintained anyways and we do not want to ship non BSD code.

Fixes pallets#833
@davidism
Copy link
Member

davidism commented Apr 5, 2018

Looks fine, but needs a test. In what circumstances is _debug_info empty?

@captainmalloc
Copy link
Contributor Author

This happened when the exception was on python callback in a custom extension. I'll try to build a simple test case.

jdufresne and others added 20 commits August 29, 2018 21:03
Add trove classifier for PyPy support
Trim trailing white space throughout the project
Pass python_requires argument to setuptools
parser: Fix typo `self.lineno` -> `token.lineno`
easy_install is deprecated and its use is discouraged by PyPA:

https://setuptools.readthedocs.io/en/latest/easy_install.html

> Warning: Easy Install is deprecated. Do not use it. Instead use pip.

Follow upstream advice and only recommended supported tools. Replace
with pip.
Clarify in docs that last filter doesn't work with generators
Remove reference to deprecated easy_install; use pip instead
This example attempts to handle both Windows-style and Unix-style line endings, but does it wrong; as noted at https://stackoverflow.com/q/12521127/1709587, the regex here will match a single \r\n as if it were a double line-break, which results in all single Windows-style line-breaks getting converted into <p> breaks instead of <br> breaks as intended.

This patch fixes that by applying Alan Moore's proposed fix from https://stackoverflow.com/a/12521544/1709587 of using a negative lookahead so that a \r cannot be counted as a line break if it is followed by a \n (while still allowing the \r\n combination to count as a line break).
Add testing and document support for Python 3.7 & pypy3
@davidism davidism closed this Mar 19, 2019
@davidism davidism reopened this Mar 19, 2019
@davidism davidism changed the base branch from 2.10-maintenance to 2.10.x April 6, 2019 20:44
@davidism
Copy link
Member

Duplicate of #674

@davidism davidism marked this as a duplicate of #674 Oct 13, 2019
@davidism davidism closed this Oct 13, 2019
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 13, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet