Skip to content

Commit

Permalink
fix: avoid closing the script tag early by escaping a forward slash
Browse files Browse the repository at this point in the history
Closes jupyter#1562
Closes jupyter#802
Related jupyter#804
  • Loading branch information
maartenbreddels committed Oct 27, 2021
1 parent 16d5bd9 commit 0252cfa
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 2 deletions.
3 changes: 3 additions & 0 deletions nbconvert/exporters/templateexporter.py
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,9 @@
'get_metadata': filters.get_metadata,
'convert_pandoc': filters.convert_pandoc,
'json_dumps': json.dumps,
# browsers will parse </script>, closing a script tag early
# Since JSON allows escaping forward slash, this will still be parsed by JSON
'escape_html_script': lambda x: x.replace('</script>', '<\\/script>'),
'strip_trailing_newline': filters.strip_trailing_newline,
'text_base64': filters.text_base64,
}
Expand Down
2 changes: 1 addition & 1 deletion share/jupyter/nbconvert/templates/classic/base.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ var element = $('#{{ div_id }}');
{% set mimetype = 'application/vnd.jupyter.widget-state+json'%}
{% if mimetype in nb.metadata.get("widgets",{})%}
<script type="{{ mimetype }}">
{{ nb.metadata.widgets[mimetype] | json_dumps }}
{{ nb.metadata.widgets[mimetype] | json_dumps | escape_html_script }}
</script>
{% endif %}
{{ super() }}
Expand Down
2 changes: 1 addition & 1 deletion share/jupyter/nbconvert/templates/lab/base.html.j2
Original file line number Diff line number Diff line change
Expand Up @@ -273,7 +273,7 @@ var element = document.getElementById('{{ div_id }}');
{% set mimetype = 'application/vnd.jupyter.widget-state+json'%}
{% if mimetype in nb.metadata.get("widgets",{})%}
<script type="{{ mimetype }}">
{{ nb.metadata.widgets[mimetype] | json_dumps }}
{{ nb.metadata.widgets[mimetype] | json_dumps | escape_html_script }}
</script>
{% endif %}
{{ super() }}
Expand Down

0 comments on commit 0252cfa

Please sign in to comment.