From b93d8e73a2274d20edef789b64650b8dc1602c5d Mon Sep 17 00:00:00 2001 From: ramki-bruno Date: Tue, 15 Apr 2025 21:45:56 +0530 Subject: [PATCH] Allow leading dot for file and folder names Co-authored-by: vishnuprasanth-j --- packages/bruno-app/src/utils/common/regex.js | 4 ++-- packages/bruno-electron/src/utils/filesystem.js | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/packages/bruno-app/src/utils/common/regex.js b/packages/bruno-app/src/utils/common/regex.js index ebdd6c453..a8e4c6eee 100644 --- a/packages/bruno-app/src/utils/common/regex.js +++ b/packages/bruno-app/src/utils/common/regex.js @@ -1,6 +1,6 @@ const invalidCharacters = /[<>:"/\\|?*\x00-\x1F]/g; // replace invalid characters with hyphens const reservedDeviceNames = /^(CON|PRN|AUX|NUL|COM[0-9]|LPT[0-9])$/i; -const firstCharacter = /^[^.\s\-<>:"/\\|?*\x00-\x1F]/; // no dot, space, hyphen and `invalidCharacters` +const firstCharacter = /^[^\s\-<>:"/\\|?*\x00-\x1F]/; // no space, hyphen and `invalidCharacters` const middleCharacters = /^[^<>:"/\\|?*\x00-\x1F]*$/; // no `invalidCharacters` const lastCharacter = /[^.\s<>:"/\\|?*\x00-\x1F]$/; // no dot, space and `invalidCharacters` @@ -9,7 +9,7 @@ export const variableNameRegex = /^[\w-.]*$/; export const sanitizeName = (name) => { name = name .replace(invalidCharacters, '-') // replace invalid characters with hyphens - .replace(/^[.\s\-]+/, '') // remove leading dots, spaces and hyphens + .replace(/^[\s\-]+/, '') // remove leading spaces and hyphens .replace(/[.\s]+$/, ''); // remove trailing dots and spaces return name; }; diff --git a/packages/bruno-electron/src/utils/filesystem.js b/packages/bruno-electron/src/utils/filesystem.js index f623e9990..328b72d18 100644 --- a/packages/bruno-electron/src/utils/filesystem.js +++ b/packages/bruno-electron/src/utils/filesystem.js @@ -165,7 +165,7 @@ const sanitizeName = (name) => { const invalidCharacters = /[<>:"/\\|?*\x00-\x1F]/g; name = name .replace(invalidCharacters, '-') // replace invalid characters with hyphens - .replace(/^[.\s\-]+/, '') // remove leading dots, spaces and hyphens + .replace(/^[\s\-]+/, '') // remove leading spaces and hyphens .replace(/[.\s]+$/, ''); // remove trailing dots and spaces return name; }; @@ -177,7 +177,7 @@ const isWindowsOS = () => { const validateName = (name) => { const invalidCharacters = /[<>:"/\\|?*\x00-\x1F]/g; // keeping this for informational purpose const reservedDeviceNames = /^(CON|PRN|AUX|NUL|COM[0-9]|LPT[0-9])$/i; - const firstCharacter = /^[^.\s\-<>:"/\\|?*\x00-\x1F]/; // no dot, space, hyphen and `invalidCharacters` + const firstCharacter = /^[^\s\-<>:"/\\|?*\x00-\x1F]/; // no space, hyphen and `invalidCharacters` const middleCharacters = /^[^<>:"/\\|?*\x00-\x1F]*$/; // no `invalidCharacters` const lastCharacter = /[^.\s<>:"/\\|?*\x00-\x1F]$/; // no dot, space and `invalidCharacters` if (name.length > 255) return false; // max name length