File tree Expand file tree Collapse file tree 2 files changed +4
-5
lines changed Expand file tree Collapse file tree 2 files changed +4
-5
lines changed Original file line number Diff line number Diff line change 99import pytest
1010
1111import plotly
12+ from plotly .offline import get_plotlyjs
1213import plotly .io as pio
1314from plotly .io ._utils import plotly_cdn_url
15+ from plotly .io ._html import _generate_sri_hash
1416
1517packages_root = os .path .dirname (
1618 os .path .dirname (os .path .dirname (os .path .dirname (os .path .realpath (plotly .__file__ ))))
3739 <script type="text/javascript">\
3840 window.PlotlyConfig = {MathJaxConfig: 'local'};</script>"""
3941
40- cdn_script = '<script charset="utf-8" src="{cdn_url}"' .format (cdn_url = plotly_cdn_url ())
42+ cdn_script = '<script charset="utf-8" src="{cdn_url}" integrity="{js_hash}" crossorigin="anonymous"></script> ' .format (cdn_url = plotly_cdn_url (), js_hash = _generate_sri_hash ( get_plotlyjs () ))
4143
4244directory_script = '<script charset="utf-8" src="plotly.min.js"></script>'
4345
Original file line number Diff line number Diff line change 22
33import pytest
44import numpy as np
5+ import re
56
67
78import plotly .graph_objs as go
@@ -59,8 +60,6 @@ def test_cdn_includes_integrity_attribute(fig1):
5960 assert 'crossorigin="anonymous"' in html_output
6061
6162 # Verify it's in the correct script tag
62- import re
63-
6463 cdn_pattern = re .compile (
6564 r'<script[^>]*src="'
6665 + re .escape (plotly_cdn_url ())
@@ -75,8 +74,6 @@ def test_cdn_integrity_hash_matches_bundled_content(fig1):
7574 html_output = pio .to_html (fig1 , include_plotlyjs = "cdn" )
7675
7776 # Extract the integrity hash from the HTML output
78- import re
79-
8077 integrity_pattern = re .compile (r'integrity="(sha256-[A-Za-z0-9+/=]+)"' )
8178 match = integrity_pattern .search (html_output )
8279 assert match is not None , "Integrity attribute not found"
You can’t perform that action at this time.
0 commit comments