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 linters #1825

Merged
merged 3 commits into from
Aug 9, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion nbconvert/exporters/html.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@

import base64
import json
from lxml.html.clean import clean_html
import mimetypes
import os
from pathlib import Path
Expand Down
4 changes: 2 additions & 2 deletions nbconvert/exporters/templateexporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,8 @@
# Distributed under the terms of the Modified BSD License.


import json
import html
from lxml.html.clean import clean_html
import json
import os
import uuid
import warnings
Expand All @@ -23,6 +22,7 @@
TemplateNotFound,
)
from jupyter_core.paths import jupyter_path
from lxml.html.clean import clean_html
from traitlets import Bool, Dict, HasTraits, List, Unicode, default, observe, validate
from traitlets.config import Config
from traitlets.utils.importstring import import_item
Expand Down
22 changes: 12 additions & 10 deletions nbconvert/exporters/tests/test_html.py
Original file line number Diff line number Diff line change
Expand Up @@ -137,9 +137,9 @@ def test_basic_name(self):

def test_javascript_injection(self):
for template in ["lab", "classic", "reveal"]:
(output, resources) = HTMLExporter(
template_name=template
).from_filename(self._get_notebook('notebook_inject.ipynb'))
(output, resources) = HTMLExporter(template_name=template).from_filename(
self._get_notebook("notebook_inject.ipynb")
)

# Check injection in the metadata.title of the Notebook
assert "<script>alert('title')</script>" not in output
Expand Down Expand Up @@ -170,14 +170,17 @@ def test_javascript_injection(self):
assert "<script>alert('output.metadata.height png injection')</script>" not in output

# Check injection in widget view
assert "<script>alert('output.data.application/vnd.jupyter.widget-view+json injection')" not in output
assert (
"<script>alert('output.data.application/vnd.jupyter.widget-view+json injection')"
not in output
)

# By design, text/html, text/markdown, application/javascript and markdown cells should allow
# for JavaScript code execution
for template in ["lab", "classic", "reveal"]:
(output, resources) = HTMLExporter(
template_name=template
).from_filename(self._get_notebook('notebook_inject.ipynb'))
(output, resources) = HTMLExporter(template_name=template).from_filename(
self._get_notebook("notebook_inject.ipynb")
)

assert "<script>alert('markdown cell')</script>" in output
assert "<script>alert('text/markdown output')</script>" in output
Expand All @@ -187,9 +190,8 @@ def test_javascript_injection(self):
# But it's an opt-out
for template in ["lab", "classic", "reveal"]:
(output, resources) = HTMLExporter(
template_name=template,
sanitize_html=True
).from_filename(self._get_notebook('notebook_inject.ipynb'))
template_name=template, sanitize_html=True
).from_filename(self._get_notebook("notebook_inject.ipynb"))

assert "<script>alert('markdown cell')</script>" not in output
assert "<script>alert('text/markdown output')</script>" not in output
Expand Down
4 changes: 3 additions & 1 deletion nbconvert/filters/highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,9 @@ def __call__(self, source, language=None, metadata=None):
return _pygments_highlight(
source if len(source) > 0 else " ",
# needed to help post processors:
HtmlFormatter(cssclass=escape(f" highlight hl-{language}"), **self.extra_formatter_options),
HtmlFormatter(
cssclass=escape(f" highlight hl-{language}"), **self.extra_formatter_options
),
language,
metadata,
)
Expand Down
2 changes: 1 addition & 1 deletion nbconvert/filters/tests/test_highlight.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ def test_parse_html_many_lang(self):
@pytest.mark.filterwarnings("ignore")
def test_inject_html(self):
out = highlight2html(self.tests[0], 'ipython3-foo"><script>alert(1)</script>')
assert '<script>alert(1)</script>' not in out
assert "<script>alert(1)</script>" not in out

def _extract_tokens(self, root, cls):
return set(map(lambda x: x.text, root.findall(".//*[@class='" + cls + "']")))
Expand Down
4 changes: 2 additions & 2 deletions nbconvert/tests/test_nbconvertapp.py
Original file line number Diff line number Diff line change
Expand Up @@ -374,7 +374,7 @@ def test_no_input(self):
'<span class="o">=</span> '
'<span class="n">symbols</span>'
'<span class="p">(</span>'
'<span class="s1">\'x y z\'</span>'
"<span class=\"s1\">'x y z'</span>"
'<span class="p">)</span>'
) not in text
self.nbconvert("notebook1.ipynb --log-level 0 --to html")
Expand All @@ -392,7 +392,7 @@ def test_no_input(self):
'<span class="o">=</span> '
'<span class="n">symbols</span>'
'<span class="p">(</span>'
'<span class="s1">\'x y z\'</span>'
"<span class=\"s1\">'x y z'</span>"
'<span class="p">)</span>'
) in text2

Expand Down