|
388 | 388 | } else { |
389 | 389 | output = item[key]; |
390 | 390 | } |
391 | | - html.push('<td onclick=' + onclick_call +'>' + output +'</td>'); |
| 391 | + html.push('<td onclick=' + onclick_call +'>' + escapeHtml(output) +'</td>'); |
392 | 392 | } |
393 | 393 | } |
394 | 394 | html.push("</tr>"); |
|
615 | 615 | } |
616 | 616 | } |
617 | 617 |
|
| 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, "&") |
| 623 | + .replace(/</g, "<") |
| 624 | + .replace(/>/g, ">") |
| 625 | + .replace(/"/g, """) |
| 626 | + .replace(/'/g, "'"); |
| 627 | + } |
| 628 | + return unsafe; |
| 629 | + } |
| 630 | + |
618 | 631 | 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 | + }); |
626 | 639 |
|
627 | 640 |
|
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; |
631 | 644 |
|
632 | | - const output = [...selected_count_items].filter(elem => elem.className == test_class); |
| 645 | + const output = [...selected_count_items].filter(elem => elem.className == test_class); |
633 | 646 | 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; |
636 | 649 | } |
637 | 650 | } |
638 | 651 |
|
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(/&/g, "&") |
| 656 | + .replace(/</g, "<") |
| 657 | + .replace(/>/g, ">") |
| 658 | + .replace(/"/g, '"') |
| 659 | + .replace(/'/g, "'"); |
| 660 | + } |
| 661 | + return htmlStr; |
642 | 662 | } |
643 | 663 |
|
644 | 664 | // For getting contents of output into json string for testing |
|
652 | 672 | } |
653 | 673 | // alert(output); |
654 | 674 | // Copy to clipboard. |
655 | | - navigator.clipboard.writeText(unEscape(output)); |
| 675 | + navigator.clipboard.writeText(unescapeHtml(output)); |
656 | 676 | } |
657 | 677 |
|
658 | 678 | // On hover, show the difference between expected and actual result |
|
0 commit comments