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 issue #453 jinja2 template select_autoescape when using jinja2.select_autoescape #454

Merged
merged 7 commits into from Jul 11, 2022

Conversation

kinow
Copy link
Contributor

@kinow kinow commented Feb 10, 2019

Hi,

I added a test to reproduce what was reported in #453 . Running the test first, without the patch, gives:

Captured traceback:
~~~~~~~~~~~~~~~~~~~
    b'Traceback (most recent call last):'
    b'  File "/home/kinow/Development/python/workspace/bandit/tests/functional/test_functional.py", line 504, in test_jinja2_templating'
    b"    self.check_example('jinja2_templating.py', expect)"
    b'  File "/home/kinow/Development/python/workspace/bandit/tests/functional/test_functional.py", line 86, in check_example'
    b'    self.assertDictEqual(expect, result)'
    b'  File "/home/kinow/Development/python/anaconda3/lib/python3.7/site-packages/unittest2/case.py", line 1128, in assertDictEqual'
    b'    self.fail(self._formatMessage(msg, standardMsg))'
    b'  File "/home/kinow/Development/python/anaconda3/lib/python3.7/site-packages/unittest2/case.py", line 690, in fail'
    b'    raise self.failureException(msg)'
    b"AssertionError: {'SEV[51 chars]GH': 5}, 'CONFIDENCE': {'UNDEFINED': 0, 'LOW':[23 chars]: 3}} != {'SEV[51 chars]GH': 6}, 'CONFIDENCE': {'UNDEFINED': 0, 'LOW':[23 chars]: 3}}"
    b"- {'CONFIDENCE': {'HIGH': 3, 'LOW': 0, 'MEDIUM': 2, 'UNDEFINED': 0},"
    b'?                                                ^'
    b''
    b"+ {'CONFIDENCE': {'HIGH': 3, 'LOW': 0, 'MEDIUM': 3, 'UNDEFINED': 0},"
    b'?                                                ^'
    b''
    b"-  'SEVERITY': {'HIGH': 5, 'LOW': 0, 'MEDIUM': 0, 'UNDEFINED': 0}}"
    b'?                       ^'
    b''
    b"+  'SEVERITY': {'HIGH': 6, 'LOW': 0, 'MEDIUM': 0, 'UNDEFINED': 0}}"
    b'?                       ^'
    b''
    b''


======
Totals
======
Ran: 244 tests in 4.4894 sec.
 - Passed: 243
 - Skipped: 0
 - Expected Fail: 0
 - Unexpected Success: 0
 - Failed: 1

Hopefully Travis CI will report that this patch produced no failures in the tests. I avoided trying to check if the jinja2 module was aliased, as I think we would have to look at the Context imports, store in a variable what was the method, and add yet another if for that? But if there's a simpler way or if necessary, happy to update this pull request.

Cheers
Bruno

@kinow kinow force-pushed the fix-jinja2-template branch 3 times, most recently from 7a73f85 to addccf9 Compare March 25, 2019 07:04
@kinow
Copy link
Contributor Author

kinow commented Mar 25, 2019

Aarrgh. Had a hard time fixing flake8 style issues, sorry. Sometimes it can be quite tricky to format everything under 80 columns :-) Rebased.

Copy link
Member

@ericwb ericwb left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

LGTM

@kinow
Copy link
Contributor Author

kinow commented Jul 11, 2022

Thanks for reviewing and sorting out formatting and last touches to get it merged, @ericwb 👍

@kinow kinow deleted the fix-jinja2-template branch July 11, 2022 00:32
@mportesdev
Copy link
Contributor

@ericwb Hi Eric, I think issue #711 and PR #903 can also be closed after this merge.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants