From 1ed5c509647dec661ce74ad28a063db3bb0e774a Mon Sep 17 00:00:00 2001 From: Harsh Chiki Date: Wed, 23 Jul 2025 14:43:07 +0530 Subject: [PATCH] Git Repo Issue 132: Allow spaces in folder names, without replacing them with space --- e2e/filesystem-upload.test.js | 48 ++++++++++----------- src/constants.js | 2 +- test/filesystem-upload-item-manager.test.js | 4 +- test/filesystem-upload-options.test.js | 13 +++++- test/filesystem-upload-utils.test.js | 24 ++++++++++- 5 files changed, 62 insertions(+), 29 deletions(-) diff --git a/e2e/filesystem-upload.test.js b/e2e/filesystem-upload.test.js index 24fb96d..1b91678 100644 --- a/e2e/filesystem-upload.test.js +++ b/e2e/filesystem-upload.test.js @@ -163,7 +163,7 @@ describe('FileSystemUpload end-to-end tests', function () { await verifyExistsInAemAndHasEvents(uploadOptions, '/freeride-steep.jpg'); await verifyExistsInAemAndHasEvents(uploadOptions, '/ice-climbing.jpg'); await verifyExistsInAemAndHasEvents(uploadOptions, `/${ENCODED_ASSET1}`); - should(await doesAemPathExist(uploadOptions, '/dir-1')).not.be.ok(); + should(await doesAemPathExist(uploadOptions, '/Dir 1')).not.be.ok(); return deleteAemPath(uploadOptions); }); @@ -197,23 +197,23 @@ describe('FileSystemUpload end-to-end tests', function () { retryErrors: [], createdFolders: [ buildFolderResult(targetFolder, '/images', 'images', uploadResult.createdFolders[2].elapsedTime), - buildFolderResult(targetFolder, '/images/dir-1', 'Dir 1', uploadResult.createdFolders[3].elapsedTime), - buildFolderResult(targetFolder, '/images/dir-1/folder_♂♀°′″℃$£‰§№¢℡㈱', 'folder_♂♀°′″℃$£‰§№¢℡㈱', uploadResult.createdFolders[4].elapsedTime), - buildFolderResult(targetFolder, '/images/dir-1/subdir1', 'subdir1', uploadResult.createdFolders[5].elapsedTime), - buildFolderResult(targetFolder, '/images/dir-1/subdir2', 'subdir2', uploadResult.createdFolders[6].elapsedTime), + buildFolderResult(targetFolder, '/images/Dir 1', 'Dir 1', uploadResult.createdFolders[3].elapsedTime), + buildFolderResult(targetFolder, '/images/Dir 1/folder_♂♀°′″℃$£‰§№¢℡㈱', 'folder_♂♀°′″℃$£‰§№¢℡㈱', uploadResult.createdFolders[4].elapsedTime), + buildFolderResult(targetFolder, '/images/Dir 1/subdir1', 'subdir1', uploadResult.createdFolders[5].elapsedTime), + buildFolderResult(targetFolder, '/images/Dir 1/subdir2', 'subdir2', uploadResult.createdFolders[6].elapsedTime), ], detailedResult: [ buildFileResult(targetFolder, '/images/Freeride-extreme.jpg', '/images/Freeride#extreme.jpg', 246578), buildFileResult(targetFolder, '/images/climber-ferrata-la-torre-di-toblin.jpg', 'images/climber-ferrata-la-torre-di-toblin.jpg', 414164), buildFileResult(targetFolder, '/images/freeride-siberia.jpg', 'images/freeride-siberia.jpg', 282584), - buildFileResult(targetFolder, '/images/dir-1/freeride-steep.jpg', '/images/Dir 1/freeride-steep.jpg', 320669), - buildFileResult(targetFolder, '/images/dir-1/freeride.jpg', '/images/Dir 1/freeride.jpg', 102189), - buildFileResult(targetFolder, '/images/dir-1/ice-climbing.jpg', '/images/Dir 1/ice-climbing.jpg', 166077), - buildFileResult(targetFolder, '/images/dir-1/이두吏讀.jpg', '/images/Dir 1/이두吏讀.jpg', 295623), - buildFileResult(targetFolder, '/images/dir-1/folder_♂♀°′″℃$£‰§№¢℡㈱/郎礼.jpg', '/images/Dir 1/folder_♂♀°′″℃$£‰§№¢℡㈱/郎礼.jpg', 161221), - buildFileResult(targetFolder, '/images/dir-1/subdir1/ski touring.jpg', '/images/Dir 1/subdir1/ski touring.jpg', 196310), - buildFileResult(targetFolder, '/images/dir-1/subdir1/skiing_2.jpg', '/images/Dir 1/subdir1/skiing_2.jpg', 245780), - buildFileResult(targetFolder, '/images/dir-1/subdir1/skiing_1.jpg', '/images/Dir 1/subdir1/skiing_1.jpg', 561767), + buildFileResult(targetFolder, '/images/Dir 1/freeride-steep.jpg', '/images/Dir 1/freeride-steep.jpg', 320669), + buildFileResult(targetFolder, '/images/Dir 1/freeride.jpg', '/images/Dir 1/freeride.jpg', 102189), + buildFileResult(targetFolder, '/images/Dir 1/ice-climbing.jpg', '/images/Dir 1/ice-climbing.jpg', 166077), + buildFileResult(targetFolder, '/images/Dir 1/이두吏讀.jpg', '/images/Dir 1/이두吏讀.jpg', 295623), + buildFileResult(targetFolder, '/images/Dir 1/folder_♂♀°′″℃$£‰§№¢℡㈱/郎礼.jpg', '/images/Dir 1/folder_♂♀°′″℃$£‰§№¢℡㈱/郎礼.jpg', 161221), + buildFileResult(targetFolder, '/images/Dir 1/subdir1/ski touring.jpg', '/images/Dir 1/subdir1/ski touring.jpg', 196310), + buildFileResult(targetFolder, '/images/Dir 1/subdir1/skiing_2.jpg', '/images/Dir 1/subdir1/skiing_2.jpg', 245780), + buildFileResult(targetFolder, '/images/Dir 1/subdir1/skiing_1.jpg', '/images/Dir 1/subdir1/skiing_1.jpg', 561767), buildFileResult(targetFolder, '/climber-ferrata-la-torre-di-toblin.jpg', '/images/climber-ferrata-la-torre-di-toblin.jpg', 414164), buildFileResult(targetFolder, '/skiing_1.jpg', 'images/Dir 1/subdir1/skiing_1.jpg', 561767), ], @@ -229,22 +229,22 @@ describe('FileSystemUpload end-to-end tests', function () { await verifyExistsInAemAndHasEvents(uploadOptions, '/images/freeride-siberia.jpg'); // images/dir1 - await verifyExistsInAemAndHasTitle(uploadOptions, '/images/dir-1', 'Dir 1'); - await verifyExistsInAemAndHasEvents(uploadOptions, '/images/dir-1/freeride.jpg'); - await verifyExistsInAemAndHasEvents(uploadOptions, '/images/dir-1/freeride-steep.jpg'); - await verifyExistsInAemAndHasEvents(uploadOptions, '/images/dir-1/ice-climbing.jpg'); - await verifyExistsInAemAndHasEvents(uploadOptions, `/images/dir-1/${ENCODED_ASSET1}`); + await verifyExistsInAemAndHasTitle(uploadOptions, '/images/Dir 1', 'Dir 1'); + await verifyExistsInAemAndHasEvents(uploadOptions, '/images/Dir 1/freeride.jpg'); + await verifyExistsInAemAndHasEvents(uploadOptions, '/images/Dir 1/freeride-steep.jpg'); + await verifyExistsInAemAndHasEvents(uploadOptions, '/images/Dir 1/ice-climbing.jpg'); + await verifyExistsInAemAndHasEvents(uploadOptions, `/images/Dir 1/${ENCODED_ASSET1}`); // images/dir1/subdir1 - await verifyExistsInAemAndHasEvents(uploadOptions, '/images/dir-1/subdir1/ski touring.jpg'); - await verifyExistsInAemAndHasEvents(uploadOptions, '/images/dir-1/subdir1/skiing_1.jpg'); - await verifyExistsInAemAndHasEvents(uploadOptions, '/images/dir-1/subdir1/skiing_2.jpg'); + await verifyExistsInAemAndHasEvents(uploadOptions, '/images/Dir 1/subdir1/ski touring.jpg'); + await verifyExistsInAemAndHasEvents(uploadOptions, '/images/Dir 1/subdir1/skiing_1.jpg'); + await verifyExistsInAemAndHasEvents(uploadOptions, '/images/Dir 1/subdir1/skiing_2.jpg'); // images/dir1/folder_♂♀°′″℃$£‰§№¢℡㈱ - await verifyExistsInAemAndHasEvents(uploadOptions, `/images/dir-1/${ENCODED_FOLDER}/${ENCODED_ASSET2}`); + await verifyExistsInAemAndHasEvents(uploadOptions, `/images/Dir 1/${ENCODED_FOLDER}/${ENCODED_ASSET2}`); - should(hasEventCheck('foldercreated', targetFolder, '/images/dir-1/subdir2', (data) => data.targetFolder)).be.ok(); - should(await doesAemPathExist(uploadOptions, '/images/dir-1/subdir2')).be.ok(); + should(hasEventCheck('foldercreated', targetFolder, '/images/Dir 1/subdir2', (data) => data.targetFolder)).be.ok(); + should(await doesAemPathExist(uploadOptions, '/images/Dir 1/subdir2')).be.ok(); return deleteAemPath(uploadOptions); }); diff --git a/src/constants.js b/src/constants.js index da8ce97..ccaffeb 100644 --- a/src/constants.js +++ b/src/constants.js @@ -55,7 +55,7 @@ module.exports.RegularExpressions = { * Will match values that contain characters that are invalid in AEM folder node * names. */ - INVALID_FOLDER_CHARACTERS_REGEX: /[.%;#+?^{}\s"&]/g, + INVALID_FOLDER_CHARACTERS_REGEX: /[.%;#+?^{}"&]/g, /** * Will match values that contain characters that are invalid in AEM asset node diff --git a/test/filesystem-upload-item-manager.test.js b/test/filesystem-upload-item-manager.test.js index 53aa164..fb434e2 100644 --- a/test/filesystem-upload-item-manager.test.js +++ b/test/filesystem-upload-item-manager.test.js @@ -34,7 +34,7 @@ describe('FileSystemUploadItemManager Tests', () => { const subChild = await manager.getDirectory('/fake/test/directory/Child Dir/Sub Child/'); should(subChild).be.ok(); should(subChild.getLocalPath()).be.exactly('/fake/test/directory/Child Dir/Sub Child'); - should(subChild.getRemotePath()).be.exactly('/content/dam/target/directory/child-dir/sub-child'); + should(subChild.getRemotePath()).be.exactly('/content/dam/target/directory/child dir/sub child'); should(subChild.getName()).be.exactly('Sub Child'); should(manager.hasDirectory('/fake/test/directory/')).be.ok(); should(manager.hasDirectory('/fake/test/directory/Child Dir')).be.ok(); @@ -44,7 +44,7 @@ describe('FileSystemUploadItemManager Tests', () => { const child = await manager.getDirectory('/fake/test/directory/Child Dir'); should(child).be.ok(); should(child.getLocalPath()).be.exactly('/fake/test/directory/Child Dir'); - should(child.getRemotePath()).be.exactly('/content/dam/target/directory/child-dir'); + should(child.getRemotePath()).be.exactly('/content/dam/target/directory/child dir'); should(child.getName()).be.exactly('Child Dir'); should(manager.getDirectory('/fake/test')).be.rejected(); diff --git a/test/filesystem-upload-options.test.js b/test/filesystem-upload-options.test.js index a2a625b..e7fce91 100644 --- a/test/filesystem-upload-options.test.js +++ b/test/filesystem-upload-options.test.js @@ -53,7 +53,7 @@ describe('FileSystemUploadOptions Tests', () => { copiedOptions = FileSystemUploadOptions.fromOptions(fileOptions); should(copiedOptions).be.ok(); should(copiedOptions.getInvalidCharacterReplaceValue()).be.exactly('-'); - should(await copiedOptions.getFolderNodeNameProcessor()('folder name')).be.exactly('folder-name'); + should(await copiedOptions.getFolderNodeNameProcessor()('folder name')).be.exactly('folder name'); should(await copiedOptions.getAssetNodeNameProcessor()('asset#name')).be.exactly('asset-name'); }); @@ -83,4 +83,15 @@ describe('FileSystemUploadOptions Tests', () => { options.withInvalidCharacterReplaceValue(':'); }); }); + + it('test folder names with spaces', async () => { + // Test that spaces are preserved in folder names + should(await options.getFolderNodeNameProcessor()('My Folder')).be.exactly('my folder'); + should(await options.getFolderNodeNameProcessor()('Folder With Spaces')).be.exactly('folder with spaces'); + should(await options.getFolderNodeNameProcessor()('Folder-With-Hyphens')).be.exactly('folder-with-hyphens'); + + // Test that other invalid characters are still replaced + should(await options.getFolderNodeNameProcessor()('Folder#With#Hash')).be.exactly('folder-with-hash'); + should(await options.getFolderNodeNameProcessor()('Folder%With%Percent')).be.exactly('folder-with-percent'); + }); }); diff --git a/test/filesystem-upload-utils.test.js b/test/filesystem-upload-utils.test.js index 8028744..cb875fe 100644 --- a/test/filesystem-upload-utils.test.js +++ b/test/filesystem-upload-utils.test.js @@ -24,7 +24,7 @@ describe('FileSystemUploadUtils Tests', () => { }); it('test clean folder name', async () => { - should(await cleanFolderName(options, 'A b:c.d')).be.exactly('a-b-c-d'); + should(await cleanFolderName(options, 'A b:c.d')).be.exactly('a b-c-d'); options.withFolderNodeNameProcessor(async (folderName) => folderName) .withInvalidCharacterReplaceValue('_'); should(await cleanFolderName(options, 'A b:c')).be.exactly('A b_c'); @@ -36,4 +36,26 @@ describe('FileSystemUploadUtils Tests', () => { .withInvalidCharacterReplaceValue('_'); should(await cleanAssetName(options, 'A #b:c')).be.exactly('A #b_c'); }); + + it('test folder names with spaces', async () => { + // Test that spaces are preserved in folder names + should(await cleanFolderName(options, 'My Folder')).be.exactly('my folder'); + should(await cleanFolderName(options, 'Folder With Spaces')).be.exactly('folder with spaces'); + should(await cleanFolderName(options, 'Folder-With-Hyphens')).be.exactly('folder-with-hyphens'); + + // Test that other invalid characters are still replaced + should(await cleanFolderName(options, 'Folder#With#Hash')).be.exactly('folder-with-hash'); + should(await cleanFolderName(options, 'Folder%With%Percent')).be.exactly('folder-with-percent'); + }); + + it('test asset names with spaces', async () => { + // Test that spaces are preserved in asset names + should(await cleanAssetName(options, 'My File.jpg')).be.exactly('My File.jpg'); + should(await cleanAssetName(options, 'File With Spaces.png')).be.exactly('File With Spaces.png'); + should(await cleanAssetName(options, 'File-With-Hyphens.pdf')).be.exactly('File-With-Hyphens.pdf'); + + // Test that other invalid characters are still replaced + should(await cleanAssetName(options, 'File#With#Hash.jpg')).be.exactly('File-With-Hash.jpg'); + should(await cleanAssetName(options, 'File%With%Percent.png')).be.exactly('File-With-Percent.png'); + }); });