Skip to content

Commit 078eced

Browse files
authored
Merge branch 'main' into issue-#1556
2 parents 72d46a0 + 510238a commit 078eced

File tree

1 file changed

+19
-16
lines changed

1 file changed

+19
-16
lines changed

website/templates/report.html

Lines changed: 19 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -356,17 +356,17 @@ <h2 class="text-2xl font-semibold leading-7 text-gray-900">
356356
const screenshots = document.getElementById('screenshots');
357357
let manage_div = document.getElementById("files_manage");
358358

359+
function escapeHtml(str) {return str.replace(/[&<>"']/g, function (s) {var entityMap = {"&": "&amp;","<": "&lt;",">": "&gt;",'"': '&quot;',"'": '&#39;',};return entityMap[s];});}
359360
function previewFile(file_name) {
360361
event.preventDefault();
361-
if (!screenshots || !(screenshots instanceof HTMLInputElement) || !screenshots.files || !screenshots.files.length) return;
362362
Array.from(screenshots.files).map(file => {
363-
if (file.name === file_name && file.type.startsWith('image/')) {
364-
let src = URL.createObjectURL(file);
365-
// Set the src attribute for the image preview
366-
$("#image-preview").attr("src", src).on('load', function() {
367-
URL.revokeObjectURL(src); // Revoke the blob URL after it's used
368-
});
369-
$("#image-preview-wrapper").css("display", "flex");
363+
if (file.name === file_name) {
364+
let src = URL.createObjectURL(file);
365+
if (src.startsWith('blob:')) {
366+
let escapedSrc = escapeHtml(src);
367+
$("#image-preview").attr("src", escapedSrc);
368+
$("#image-preview-wrapper").show();
369+
}else {$("#image-preview-wrapper").hide();}
370370
}
371371
});
372372
}
@@ -401,14 +401,17 @@ <h2 class="text-2xl font-semibold leading-7 text-gray-900">
401401

402402
fileList.map(file => {
403403
let src = URL.createObjectURL(file);
404-
$("#files_manage").append(`
405-
<div class="w-full md:w-[300px] h-[180px] overflow-hidden rounded-lg" onclick="previewFile('${file.name}')">
406-
<div class="w-full h-10 flex justify-center rounded-t-lg p-2 bg-gray-500">
407-
<p class="text-xl text-white font-bold">${file.name.slice(0,20)}...</p>
408-
</div>
409-
<img class="object-cover" src="${src}" alt="">
410-
</div>
411-
`)
404+
let safeName = $("<div>").text(file.name).html();
405+
let safeNameDisplay = safeName.slice(0, 20) + (safeName.length > 20 ? "..." : "");
406+
// Use the safe name for display and in the onclick handler
407+
let fileDiv = $("<div>").addClass("w-full md:w-[300px] h-[180px] overflow-hidden rounded-lg").attr("onclick", `previewFile('${safeName}')`);
408+
let titleDiv = $("<div>").addClass("w-full h-10 flex justify-center rounded-t-lg p-2 bg-gray-500");
409+
let titleP = $("<p>").addClass("text-xl text-white font-bold").text(safeNameDisplay);
410+
let img = $("<img>").addClass("object-cover").attr("src", escapeHtml(src));
411+
412+
titleDiv.append(titleP);
413+
fileDiv.append(titleDiv).append(img);
414+
$("#files_manage").append(fileDiv);
412415
})
413416

414417
});

0 commit comments

Comments
 (0)