Skip to content
This repository was archived by the owner on Oct 21, 2022. It is now read-only.

Commit 1e4c9fc

Browse files
authored
Fix escaping for the showDialog function. Fixes #351. (#353)
1 parent b5b071e commit 1e4c9fc

File tree

2 files changed

+33
-2
lines changed

2 files changed

+33
-2
lines changed

dashboard/grid-template.html

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -146,8 +146,7 @@
146146
{% set self_2_details = result.self_compatibility_check[1].details %}
147147
{% endif %}
148148
{% endif %}
149-
<td class="{{ bgColorName }}" onclick="showDialog(
150-
'{{ cellName|safe }}', '{{ result.status_type|safe }}', '{{ self_1_status|safe }}', '{{ self_2_status|safe }}','{{ pairwise_status|safe }}', '{{ self_1_details|replace('\n', ' ')|safe}}', '{{ self_2_details|replace('\n', ' ')|safe}}', '{{ pairwise_details|replace('\n', ' ')|safe }}')">
149+
<td class="{{ bgColorName }}" onclick="showDialog('{{ cellName|safe }}', '{{ result.status_type|safe }}', '{{ self_1_status|safe }}', '{{ self_2_status|safe }}','{{ pairwise_status|safe }}', '{{ self_1_details|replace('\\', '\\\\')|replace('\'', '\\\'')|replace('\n', ' ')}}', '{{ self_2_details|replace('\\', '\\\\')|replace('\'', '\\\'')|replace('\n', ' ')}}', '{{ pairwise_details|replace('\\', '\\\\')|replace('\'', '\\\'')|replace('\n', ' ') }}')">
151150
<div id="{{ cellName }}" class="dialog" title="{{ row_package.friendly_name }} and {{ col_package.friendly_name }}">
152151
</div>
153152
</td>

dashboard/test_dashboard_builder.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -462,6 +462,38 @@ def test_self_failure(self):
462462
html_grid = builder.build_dashboard('dashboard/grid-template.html')
463463
self.assertIn("Installation failure", html_grid)
464464

465+
def test_escape(self):
466+
"""Test that the arguments to showDialog() are escaped."""
467+
packages = [PACKAGE_1, PACKAGE_2]
468+
store = fake_compatibility_store.CompatibilityStore()
469+
store.save_compatibility_statuses([
470+
compatibility_store.CompatibilityResult(
471+
packages=[PACKAGE_1],
472+
python_major_version=3,
473+
status=compatibility_store.Status.INSTALL_ERROR,
474+
details=r"This \ has a ' in it < >"
475+
),
476+
compatibility_store.CompatibilityResult(
477+
packages=[PACKAGE_2],
478+
python_major_version=3,
479+
status=compatibility_store.Status.SUCCESS
480+
),
481+
])
482+
483+
with self.patch_finder, self.patch_highlighter:
484+
package_to_results = store.get_self_compatibilities(packages)
485+
pairwise_to_results = store.get_compatibility_combinations(
486+
packages)
487+
results = dashboard_builder._ResultHolder(package_to_results,
488+
pairwise_to_results)
489+
builder = dashboard_builder.DashboardBuilder(packages, results)
490+
html_grid = builder.build_dashboard('dashboard/grid-template.html')
491+
with open('/tmp/foo.html', 'w+') as f:
492+
f.write(html_grid)
493+
494+
self.assertIn("This \\\\ has a \\&#39; in it &lt; &gt;", html_grid)
495+
496+
465497
def test_missing_pairwise(self):
466498
"""CompatibilityResult not available for a pair of packages."""
467499
packages = [PACKAGE_1, PACKAGE_2]

0 commit comments

Comments
 (0)