| 240 | |
| 241 | |
| 242 | def test_sanitize_json(engine): |
| 243 | layout = {"title": {"text": "</script>\u2028\u2029"}} |
| 244 | fig = go.Figure(layout=layout) |
| 245 | fig_json = pio.to_json_plotly(fig, engine=engine) |
| 246 | layout_2 = json.loads(fig_json)["layout"] |
| 247 | if "template" in layout_2: |
| 248 | del layout_2["template"] |
| 249 | |
| 250 | assert layout == layout_2 |
| 251 | |
| 252 | replacements = { |
| 253 | "<": "\\u003c", |
| 254 | ">": "\\u003e", |
| 255 | "/": "\\u002f", |
| 256 | "\u2028": "\\u2028", |
| 257 | "\u2029": "\\u2029", |
| 258 | } |
| 259 | |
| 260 | for bad, good in replacements.items(): |
| 261 | assert bad not in fig_json |
| 262 | assert good in fig_json |
| 263 | |
| 264 | |
| 265 | @pytest.mark.parametrize("na_value", [np.nan, pd.NaT, pd.NA]) |