From 38b3b4ad764060af17acea646c5627c065afdceb Mon Sep 17 00:00:00 2001 From: Jim Myers Date: Tue, 4 Jun 2024 14:40:16 -0400 Subject: [PATCH 01/10] handle prohibited chars in file names --- src/js/fileupload2.js | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/src/js/fileupload2.js b/src/js/fileupload2.js index 6f563d1..0d99a4d 100644 --- a/src/js/fileupload2.js +++ b/src/js/fileupload2.js @@ -188,6 +188,10 @@ function initSpanTxt(htmlId, key) { function addMessage(type, key) { $('#messages').html('').append($('
').addClass(type).text(getLocalizedString(dvLocale, key))); } +function appendMessage(type, text) { + $('#messages').append($('
').addClass(type).text(text)); +} + async function populatePageMetadata(data) { var mdFields = data.metadataBlocks.citation.fields; var title = ""; @@ -686,8 +690,18 @@ function queueFileForDirectUpload(file) { if (!send) { row.addClass('file-exists'); } - row.append($('').prop('type', 'checkbox').prop('id', 'file_' + fileBlock.children().length).prop('checked', send)) - .append($('
').addClass('ui-fileupload-filename').text(path)) + let badChars = !(fUpload.file.name.match(/[[\/:*?|;#]/)===null); + if(badChars) { + if($('.warn').length==0) { + appendMessage('warn','The highlighted file(s) below contain one or more disallowed characters (/;:|?*#) in their filename. Disallowed characters will be replaced by an underscore (_) if the file(s) are uploaded.'); + } + } + row.append($('').prop('type', 'checkbox').prop('id', 'file_' + fileBlock.children().length).prop('checked', send)); + let fnameElement = $('
').addClass('ui-fileupload-filename').text(path); + if(badChars) { + fnameElement.addClass('badchars'); + } + row.append(fnameElement) .append($('
').text(file.size)).append($('
').addClass('ui - fileupload - progress')) .append($('
').addClass('ui - fileupload - cancel')); console.log('adding click handler for file_' + fileBlock.children().length); @@ -824,7 +838,7 @@ async function directUploadFinished() { console.log(fup.file.webkitRelativePath + ' : ' + fup.storageId); let entry = {}; entry.storageIdentifier = fup.storageId; - entry.fileName = fup.file.name; + entry.fileName = fup.file.name.replace(/[\/:*?|;#]/g,'_'); let path = fup.file.webkitRelativePath; console.log(path); path = path.substring(path.indexOf('/'), path.lastIndexOf('/')); From 42711ab3277681e4f9d1a0fa5195998bd561f261 Mon Sep 17 00:00:00 2001 From: Jim Myers Date: Tue, 4 Jun 2024 15:11:23 -0400 Subject: [PATCH 02/10] css for bad chars warning --- src/css/dvwebloader.css | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/src/css/dvwebloader.css b/src/css/dvwebloader.css index a413c03..f76292a 100644 --- a/src/css/dvwebloader.css +++ b/src/css/dvwebloader.css @@ -45,6 +45,10 @@ label { background-color: beige; padding: 10px; } +.warn { + background-color: bisque; + padding: 10px; +} .file-exists { background-color: lightblue; } @@ -67,3 +71,7 @@ h1 { width: 58%; display:inline-block; } +.badchars { + background-color: bisque; + padding: 10px; +} From 3c6af7d9de73d91a5c21c649883e6f29d7df4500 Mon Sep 17 00:00:00 2001 From: Jim Myers Date: Tue, 4 Jun 2024 16:06:41 -0400 Subject: [PATCH 03/10] i18n re: badChars --- src/js/lang.js | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/js/lang.js b/src/js/lang.js index c6ea7ba..c0f94d9 100644 --- a/src/js/lang.js +++ b/src/js/lang.js @@ -15,6 +15,7 @@ const translations = { msgNoFile: "No files to upload. Check some files, or refresh to start over.", msgUploadCompleteRegistering: "Uploads to S3 complete. Now registering all files with the dataset. This may take some time for large numbers of files.", msgUploadComplete: "Upload complete, all files in dataset. Close this window and refresh your dataset page to see the uploaded files.", + msgRequiredFileNameChange: "The highlighted file(s) below contain one or more disallowed characters (/;:|?*#) in their filename. Disallowed characters will be replaced by an underscore (_) if the file(s) are uploaded.", }, fr: { title: "Envoi d'un dossier", @@ -31,6 +32,7 @@ const translations = { msgNoFile: "Aucun fichier à envoyer. Cochez certains fichiers ou rafraîchissez la page pour recommencer.", msgUploadCompleteRegistering: "Envois vers S3 terminés. Enregistrement de tous les fichiers en cours dans le jeu de données. Cela peut prendre du temps pour un grand nombre de fichiers.", msgUploadComplete: "Envoi terminé, tous les fichiers sont dans le jeu de données. Fermez cette fenêtre et rafraîchissez la page de votre jeu de données pour voir les fichiers envoyés.", + msgRequiredFileNameChange: "Le ou les fichiers en surbrillance ci-dessous contiennent un ou plusieurs caractères non autorisés (/;:|?*#) dans leur nom de fichier. Les caractères non autorisés seront remplacés par un trait de soulignement (_) si le(s) fichier(s) sont téléchargés.", }, }; From c4d8539acac8b46669afc188e88b6d42a86cd725 Mon Sep 17 00:00:00 2001 From: Jim Myers Date: Wed, 5 Jun 2024 12:59:23 -0400 Subject: [PATCH 04/10] check for bad paths, munge path/filename before comparing with existing --- src/js/fileupload2.js | 19 +++++++++++++++++-- src/js/lang.js | 4 ++-- 2 files changed, 19 insertions(+), 4 deletions(-) diff --git a/src/js/fileupload2.js b/src/js/fileupload2.js index 0d99a4d..3299b83 100644 --- a/src/js/fileupload2.js +++ b/src/js/fileupload2.js @@ -667,8 +667,20 @@ function queueFileForDirectUpload(file) { } var fUpload = new fileUpload(file); let send = true; - let path = file.webkitRelativePath.substring(file.webkitRelativePath.indexOf('/') + 1); + let origPath = file.webkitRelativePath.substring(file.webkitRelativePath.indexOf('/') + 1); console.log(path); + let path =origPath.substring(0, origPath.length - file.name.length); + let badPath = (path.match(/^[a-zA-Z0-9_\-.\\\/ ]*$/)===null); + if(badPath) { + if($('.warn').length==0) { + addMessage('warn', 'msgRequiredFileOrPathNameChange'); + } + //Munge path according to rules + path = path.replace(/[^\w\d_\\.\\\/ ]+/g,'_'); + //Munge filename if needed + path=path.concat(file.name.replace(/[\/:*?|;#]/g,'_')); + } + //Now check versus existing files if (path in existingFiles) { send = false; } else if (removeExtension(path) in convertedFileNameMap) { @@ -697,7 +709,7 @@ function queueFileForDirectUpload(file) { } } row.append($('').prop('type', 'checkbox').prop('id', 'file_' + fileBlock.children().length).prop('checked', send)); - let fnameElement = $('
').addClass('ui-fileupload-filename').text(path); + let fnameElement = $('
').addClass('ui-fileupload-filename').text(origPath); if(badChars) { fnameElement.addClass('badchars'); } @@ -838,10 +850,13 @@ async function directUploadFinished() { console.log(fup.file.webkitRelativePath + ' : ' + fup.storageId); let entry = {}; entry.storageIdentifier = fup.storageId; + //Remove bad file name chars entry.fileName = fup.file.name.replace(/[\/:*?|;#]/g,'_'); let path = fup.file.webkitRelativePath; console.log(path); path = path.substring(path.indexOf('/'), path.lastIndexOf('/')); + //Remove bad path chars + path = path.replace(/[^\w\d_\\.\\\/ ]+/g,'_'); if (path.length !== 0) { entry.directoryLabel = path; } diff --git a/src/js/lang.js b/src/js/lang.js index c0f94d9..fb0ef63 100644 --- a/src/js/lang.js +++ b/src/js/lang.js @@ -15,7 +15,7 @@ const translations = { msgNoFile: "No files to upload. Check some files, or refresh to start over.", msgUploadCompleteRegistering: "Uploads to S3 complete. Now registering all files with the dataset. This may take some time for large numbers of files.", msgUploadComplete: "Upload complete, all files in dataset. Close this window and refresh your dataset page to see the uploaded files.", - msgRequiredFileNameChange: "The highlighted file(s) below contain one or more disallowed characters (/;:|?*#) in their filename. Disallowed characters will be replaced by an underscore (_) if the file(s) are uploaded.", + msgRequiredPatOrFileNameChange: "The highlighted path/file(s) below contain one or more disallowed characters (paths can only contain a-Z, 0-9, '_', '-', '.', '\', '/' and ' ', and filenames cannot contain any of /;:|?*#). Disallowed characters will be replaced by an underscore (_) if the file(s) are uploaded.", }, fr: { title: "Envoi d'un dossier", @@ -32,7 +32,7 @@ const translations = { msgNoFile: "Aucun fichier à envoyer. Cochez certains fichiers ou rafraîchissez la page pour recommencer.", msgUploadCompleteRegistering: "Envois vers S3 terminés. Enregistrement de tous les fichiers en cours dans le jeu de données. Cela peut prendre du temps pour un grand nombre de fichiers.", msgUploadComplete: "Envoi terminé, tous les fichiers sont dans le jeu de données. Fermez cette fenêtre et rafraîchissez la page de votre jeu de données pour voir les fichiers envoyés.", - msgRequiredFileNameChange: "Le ou les fichiers en surbrillance ci-dessous contiennent un ou plusieurs caractères non autorisés (/;:|?*#) dans leur nom de fichier. Les caractères non autorisés seront remplacés par un trait de soulignement (_) si le(s) fichier(s) sont téléchargés.", + msgRequiredFileNameChange: "Les chemins/noms de fichiers en surbrillance ci-dessous contiennent un ou plusieurs caractères non autorisés (les chemins ne peuvent contenir que a-Z, 0-9, '_', '-', '.', '\', '/' et ' ', et les noms de fichiers ne peuvent contenir aucun des éléments suivants : /;:|?*#). Les caractères non autorisés seront remplacés par un trait de soulignement (_) si le(s) fichier(s) sont téléchargés.", }, }; From ee691b748c1fd5fa0898c0ce9a6f75b49f019f12 Mon Sep 17 00:00:00 2001 From: Jim Myers Date: Wed, 5 Jun 2024 13:04:51 -0400 Subject: [PATCH 05/10] fix path munging in good case --- src/js/fileupload2.js | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/js/fileupload2.js b/src/js/fileupload2.js index 3299b83..2e38b4c 100644 --- a/src/js/fileupload2.js +++ b/src/js/fileupload2.js @@ -668,7 +668,8 @@ function queueFileForDirectUpload(file) { var fUpload = new fileUpload(file); let send = true; let origPath = file.webkitRelativePath.substring(file.webkitRelativePath.indexOf('/') + 1); - console.log(path); + console.log("Original Path: " + origPath); + //Remove filename part let path =origPath.substring(0, origPath.length - file.name.length); let badPath = (path.match(/^[a-zA-Z0-9_\-.\\\/ ]*$/)===null); if(badPath) { @@ -677,9 +678,10 @@ function queueFileForDirectUpload(file) { } //Munge path according to rules path = path.replace(/[^\w\d_\\.\\\/ ]+/g,'_'); - //Munge filename if needed - path=path.concat(file.name.replace(/[\/:*?|;#]/g,'_')); } + //Re-Add filename, munge filename if needed + path=path.concat(file.name.replace(/[\/:*?|;#]/g,'_')); + console.log("Final Path: " + path); //Now check versus existing files if (path in existingFiles) { send = false; From ff76b80485f1e31ab24751cd739c67c27799c4ce Mon Sep 17 00:00:00 2001 From: Jim Myers Date: Wed, 5 Jun 2024 13:06:51 -0400 Subject: [PATCH 06/10] i18n fix --- src/js/fileupload2.js | 7 ++----- src/js/lang.js | 4 ++-- 2 files changed, 4 insertions(+), 7 deletions(-) diff --git a/src/js/fileupload2.js b/src/js/fileupload2.js index 2e38b4c..f15f9bf 100644 --- a/src/js/fileupload2.js +++ b/src/js/fileupload2.js @@ -188,9 +188,6 @@ function initSpanTxt(htmlId, key) { function addMessage(type, key) { $('#messages').html('').append($('
').addClass(type).text(getLocalizedString(dvLocale, key))); } -function appendMessage(type, text) { - $('#messages').append($('
').addClass(type).text(text)); -} async function populatePageMetadata(data) { var mdFields = data.metadataBlocks.citation.fields; @@ -674,7 +671,7 @@ function queueFileForDirectUpload(file) { let badPath = (path.match(/^[a-zA-Z0-9_\-.\\\/ ]*$/)===null); if(badPath) { if($('.warn').length==0) { - addMessage('warn', 'msgRequiredFileOrPathNameChange'); + addMessage('warn', 'msgRequiredPathOrFileNameChange'); } //Munge path according to rules path = path.replace(/[^\w\d_\\.\\\/ ]+/g,'_'); @@ -707,7 +704,7 @@ function queueFileForDirectUpload(file) { let badChars = !(fUpload.file.name.match(/[[\/:*?|;#]/)===null); if(badChars) { if($('.warn').length==0) { - appendMessage('warn','The highlighted file(s) below contain one or more disallowed characters (/;:|?*#) in their filename. Disallowed characters will be replaced by an underscore (_) if the file(s) are uploaded.'); + addMessage('warn', 'msgRequiredPathOrFileNameChange'); } } row.append($('').prop('type', 'checkbox').prop('id', 'file_' + fileBlock.children().length).prop('checked', send)); diff --git a/src/js/lang.js b/src/js/lang.js index fb0ef63..7dccdeb 100644 --- a/src/js/lang.js +++ b/src/js/lang.js @@ -15,7 +15,7 @@ const translations = { msgNoFile: "No files to upload. Check some files, or refresh to start over.", msgUploadCompleteRegistering: "Uploads to S3 complete. Now registering all files with the dataset. This may take some time for large numbers of files.", msgUploadComplete: "Upload complete, all files in dataset. Close this window and refresh your dataset page to see the uploaded files.", - msgRequiredPatOrFileNameChange: "The highlighted path/file(s) below contain one or more disallowed characters (paths can only contain a-Z, 0-9, '_', '-', '.', '\', '/' and ' ', and filenames cannot contain any of /;:|?*#). Disallowed characters will be replaced by an underscore (_) if the file(s) are uploaded.", + msgRequiredPathOrFileNameChange: "The highlighted path/file(s) below contain one or more disallowed characters (paths can only contain a-Z, 0-9, '_', '-', '.', '\', '/' and ' ', and filenames cannot contain any of /;:|?*#). Disallowed characters will be replaced by an underscore (_) if the file(s) are uploaded.", }, fr: { title: "Envoi d'un dossier", @@ -32,7 +32,7 @@ const translations = { msgNoFile: "Aucun fichier à envoyer. Cochez certains fichiers ou rafraîchissez la page pour recommencer.", msgUploadCompleteRegistering: "Envois vers S3 terminés. Enregistrement de tous les fichiers en cours dans le jeu de données. Cela peut prendre du temps pour un grand nombre de fichiers.", msgUploadComplete: "Envoi terminé, tous les fichiers sont dans le jeu de données. Fermez cette fenêtre et rafraîchissez la page de votre jeu de données pour voir les fichiers envoyés.", - msgRequiredFileNameChange: "Les chemins/noms de fichiers en surbrillance ci-dessous contiennent un ou plusieurs caractères non autorisés (les chemins ne peuvent contenir que a-Z, 0-9, '_', '-', '.', '\', '/' et ' ', et les noms de fichiers ne peuvent contenir aucun des éléments suivants : /;:|?*#). Les caractères non autorisés seront remplacés par un trait de soulignement (_) si le(s) fichier(s) sont téléchargés.", + msgRequiredPathOrFileNameChange: "Les chemins/noms de fichiers en surbrillance ci-dessous contiennent un ou plusieurs caractères non autorisés (les chemins ne peuvent contenir que a-Z, 0-9, '_', '-', '.', '\', '/' et ' ', et les noms de fichiers ne peuvent contenir aucun des éléments suivants : /;:|?*#). Les caractères non autorisés seront remplacés par un trait de soulignement (_) si le(s) fichier(s) sont téléchargés.", }, }; From f78fd4dd463f71a9ac2740e365031915914b71a4 Mon Sep 17 00:00:00 2001 From: Jim Myers Date: Wed, 5 Jun 2024 13:10:12 -0400 Subject: [PATCH 07/10] fix regex --- src/js/fileupload2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/fileupload2.js b/src/js/fileupload2.js index f15f9bf..82b3960 100644 --- a/src/js/fileupload2.js +++ b/src/js/fileupload2.js @@ -668,7 +668,7 @@ function queueFileForDirectUpload(file) { console.log("Original Path: " + origPath); //Remove filename part let path =origPath.substring(0, origPath.length - file.name.length); - let badPath = (path.match(/^[a-zA-Z0-9_\-.\\\/ ]*$/)===null); + let badPath = (path.match(/^[a-zA-Z0-9_\-\.\\\/ ]*$/)===null); if(badPath) { if($('.warn').length==0) { addMessage('warn', 'msgRequiredPathOrFileNameChange'); From 9bf81a9163200555e37e77476f422e1eff0fff3e Mon Sep 17 00:00:00 2001 From: Jim Myers Date: Wed, 5 Jun 2024 13:19:27 -0400 Subject: [PATCH 08/10] fix highlight, cleanup warning --- src/js/fileupload2.js | 4 ++-- src/js/lang.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/js/fileupload2.js b/src/js/fileupload2.js index 82b3960..ed91791 100644 --- a/src/js/fileupload2.js +++ b/src/js/fileupload2.js @@ -668,7 +668,7 @@ function queueFileForDirectUpload(file) { console.log("Original Path: " + origPath); //Remove filename part let path =origPath.substring(0, origPath.length - file.name.length); - let badPath = (path.match(/^[a-zA-Z0-9_\-\.\\\/ ]*$/)===null); + let badPath = (path.match(/^[\w\d_\-\.\\\/ ]*$/)===null); if(badPath) { if($('.warn').length==0) { addMessage('warn', 'msgRequiredPathOrFileNameChange'); @@ -709,7 +709,7 @@ function queueFileForDirectUpload(file) { } row.append($('').prop('type', 'checkbox').prop('id', 'file_' + fileBlock.children().length).prop('checked', send)); let fnameElement = $('
').addClass('ui-fileupload-filename').text(origPath); - if(badChars) { + if(badPath || badChars) { fnameElement.addClass('badchars'); } row.append(fnameElement) diff --git a/src/js/lang.js b/src/js/lang.js index 7dccdeb..4671bc8 100644 --- a/src/js/lang.js +++ b/src/js/lang.js @@ -15,7 +15,7 @@ const translations = { msgNoFile: "No files to upload. Check some files, or refresh to start over.", msgUploadCompleteRegistering: "Uploads to S3 complete. Now registering all files with the dataset. This may take some time for large numbers of files.", msgUploadComplete: "Upload complete, all files in dataset. Close this window and refresh your dataset page to see the uploaded files.", - msgRequiredPathOrFileNameChange: "The highlighted path/file(s) below contain one or more disallowed characters (paths can only contain a-Z, 0-9, '_', '-', '.', '\', '/' and ' ', and filenames cannot contain any of /;:|?*#). Disallowed characters will be replaced by an underscore (_) if the file(s) are uploaded.", + msgRequiredPathOrFileNameChange: "The highlighted path/file(s) below contain one or more disallowed characters (paths can only contain a-Z, 0-9, '_', '-', '.', '\', '/' and ' ', and filenames cannot contain any of '/;:|?*#' ). Disallowed characters will be replaced by an underscore ('_') if the file(s) are uploaded.", }, fr: { title: "Envoi d'un dossier", @@ -32,7 +32,7 @@ const translations = { msgNoFile: "Aucun fichier à envoyer. Cochez certains fichiers ou rafraîchissez la page pour recommencer.", msgUploadCompleteRegistering: "Envois vers S3 terminés. Enregistrement de tous les fichiers en cours dans le jeu de données. Cela peut prendre du temps pour un grand nombre de fichiers.", msgUploadComplete: "Envoi terminé, tous les fichiers sont dans le jeu de données. Fermez cette fenêtre et rafraîchissez la page de votre jeu de données pour voir les fichiers envoyés.", - msgRequiredPathOrFileNameChange: "Les chemins/noms de fichiers en surbrillance ci-dessous contiennent un ou plusieurs caractères non autorisés (les chemins ne peuvent contenir que a-Z, 0-9, '_', '-', '.', '\', '/' et ' ', et les noms de fichiers ne peuvent contenir aucun des éléments suivants : /;:|?*#). Les caractères non autorisés seront remplacés par un trait de soulignement (_) si le(s) fichier(s) sont téléchargés.", + msgRequiredPathOrFileNameChange: "Le(s) chemin(s) en surbrillance ci-dessous contiennent un ou plusieurs caractères non autorisés (les chemins ne peuvent contenir que a-Z, 0-9, '_', '-', '.', '\', '/' et ' ', et les noms de fichiers ne peuvent contenir aucun des éléments '/;:|?*#' ). Les caractères non autorisés seront remplacés par un trait de soulignement (« _ ») si le(s) fichier(s) sont téléchargés.", }, }; From 62336b4785309b8942a1191d164a6df2098e42eb Mon Sep 17 00:00:00 2001 From: Jim Myers Date: Wed, 5 Jun 2024 13:28:12 -0400 Subject: [PATCH 09/10] use origPath in rawFileMap --- src/js/fileupload2.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/js/fileupload2.js b/src/js/fileupload2.js index ed91791..01629bd 100644 --- a/src/js/fileupload2.js +++ b/src/js/fileupload2.js @@ -685,7 +685,7 @@ function queueFileForDirectUpload(file) { } else if (removeExtension(path) in convertedFileNameMap) { send = false; } - rawFileMap[path] = file; + rawFileMap[origPath] = file; let i = rawFileMap.length; //startUploads(); if (send) { From 05421fc230da2c14b50b6995ff04711bec9ac5a7 Mon Sep 17 00:00:00 2001 From: Jim Myers Date: Tue, 20 Aug 2024 08:55:51 -0400 Subject: [PATCH 10/10] remove console.log msgs --- src/js/fileupload2.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/js/fileupload2.js b/src/js/fileupload2.js index 01629bd..1323571 100644 --- a/src/js/fileupload2.js +++ b/src/js/fileupload2.js @@ -665,7 +665,7 @@ function queueFileForDirectUpload(file) { var fUpload = new fileUpload(file); let send = true; let origPath = file.webkitRelativePath.substring(file.webkitRelativePath.indexOf('/') + 1); - console.log("Original Path: " + origPath); + //Remove filename part let path =origPath.substring(0, origPath.length - file.name.length); let badPath = (path.match(/^[\w\d_\-\.\\\/ ]*$/)===null); @@ -678,7 +678,7 @@ function queueFileForDirectUpload(file) { } //Re-Add filename, munge filename if needed path=path.concat(file.name.replace(/[\/:*?|;#]/g,'_')); - console.log("Final Path: " + path); + //Now check versus existing files if (path in existingFiles) { send = false;