Skip to content

Commit 1b2a290

Browse files
author
Craig Cornelius
authored
Fix getting data from output tables with left click with HTML escape/… (#496)
* Fix getting data from output tables with left click with HTML escape/unescape * Fix indenting and use of Exception
1 parent df6ddce commit 1b2a290

File tree

2 files changed

+39
-19
lines changed

2 files changed

+39
-19
lines changed

verifier/check_known_issues.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -356,7 +356,7 @@ def check_collation_issues(test):
356356
if (s1.find('\ufffd') >= 0 or s2.find('\ufffd') >=0 or
357357
('rules' in input_data and input_data['rules'].find('\ufffd'))) >= 0:
358358
return knownIssueType.collation_jsonc_bug_with_surrogates
359-
except KeyError as e:
359+
except Exception as e:
360360
return None
361361

362362

verifier/detail_template.html

Lines changed: 38 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -388,7 +388,7 @@
388388
} else {
389389
output = item[key];
390390
}
391-
html.push('<td onclick=' + onclick_call +'>' + output +'</td>');
391+
html.push('<td onclick=' + onclick_call +'>' + escapeHtml(output) +'</td>');
392392
}
393393
}
394394
html.push("</tr>");
@@ -615,30 +615,50 @@
615615
}
616616
}
617617

618+
function escapeHtml(unsafe) {
619+
// To make sure that table entries won't break the HTML code.
620+
if (typeof unsafe === 'string') {
621+
return unsafe
622+
.replace(/&/g, "&amp;")
623+
.replace(/</g, "&lt;")
624+
.replace(/>/g, "&gt;")
625+
.replace(/"/g, "&quot;")
626+
.replace(/'/g, "&#039;");
627+
}
628+
return unsafe;
629+
}
630+
618631
function clearSelectedItems(the_button, test_class) {
619-
// Clear all the check boxes for this test_class.
620-
const test_data = test_results[test_class];
621-
test_data.check_boxes.forEach((widget) => {
622-
widget.value = question_mark;
623-
const div_for_checkbox = widget.parentElement;
624-
div_for_checkbox.attributeStyleMap.clear();
625-
});
632+
// Clear all the check boxes for this test_class.
633+
const test_data = test_results[test_class];
634+
test_data.check_boxes.forEach((widget) => {
635+
widget.value = question_mark;
636+
const div_for_checkbox = widget.parentElement;
637+
div_for_checkbox.attributeStyleMap.clear();
638+
});
626639

627640

628-
// reset the number of results size
629-
const selected_count_items = document.getElementsByName('selectedCount');
630-
const newSize = test_data.selected_set == null ? 0 : test_data.all_labels.size;
641+
// reset the number of results size
642+
const selected_count_items = document.getElementsByName('selectedCount');
643+
const newSize = test_data.selected_set == null ? 0 : test_data.all_labels.size;
631644

632-
const output = [...selected_count_items].filter(elem => elem.className == test_class);
645+
const output = [...selected_count_items].filter(elem => elem.className == test_class);
633646
if (output) {
634-
// Set the current count of items
635-
output[0].innerHTML = output[0].innerText = newSize;
647+
// Set the current count of items
648+
output[0].innerHTML = output[0].innerText = newSize;
636649
}
637650
}
638651

639-
function unEscape(htmlStr) {
640-
var doc = new DOMParser().parseFromString(htmlStr, "text/html");
641-
return doc.documentElement.textContent;
652+
function unescapeHtml(htmlStr) {
653+
if (typeof htmlStr === 'string') {
654+
return htmlStr
655+
.replace(/&amp;/g, "&")
656+
.replace(/&lt;/g, "<")
657+
.replace(/&gt;/g, ">")
658+
.replace(/&quot;/g, '"')
659+
.replace(/&#039;/g, "'");
660+
}
661+
return htmlStr;
642662
}
643663

644664
// For getting contents of output into json string for testing
@@ -652,7 +672,7 @@
652672
}
653673
// alert(output);
654674
// Copy to clipboard.
655-
navigator.clipboard.writeText(unEscape(output));
675+
navigator.clipboard.writeText(unescapeHtml(output));
656676
}
657677

658678
// On hover, show the difference between expected and actual result

0 commit comments

Comments
 (0)