diff --git a/src/Terminal/DirectoryHelpers.ts b/src/Terminal/DirectoryHelpers.ts index 3b9eb0b45..fb15187b9 100644 --- a/src/Terminal/DirectoryHelpers.ts +++ b/src/Terminal/DirectoryHelpers.ts @@ -49,9 +49,11 @@ export function isValidFilename(filename: string): boolean { * not an entire path */ export function isValidDirectoryName(name: string): boolean { - // Allows alphanumerics, hyphens, underscores, and percentage signs. - // Name can begin with a single period, but otherwise cannot have any - const regex = /^\.?(?:\w[_\-.%]*)+$/; + // A valid directory name: + // Must be at least 1 character long + // Can only include characters in the character set [-.%a-zA-Z0-9_] + // Cannot end with a '.' + const regex = /^(?:[-.%]|\w)*[-%a-zA-Z0-9_]$/; // match() returns null if no match is found return name.match(regex) != null; diff --git a/test/jest/Terminal/Directory.test.js b/test/jest/Terminal/Directory.test.js index 94c3a4d2e..79db3a0a1 100644 --- a/test/jest/Terminal/Directory.test.js +++ b/test/jest/Terminal/Directory.test.js @@ -103,17 +103,18 @@ describe("Terminal Directory Tests", function () { expect(isValidDirectoryName("._foo")).toEqual(true); expect(isValidDirectoryName("_foo")).toEqual(true); expect(isValidDirectoryName("foo.dir")).toEqual(true); - expect(isValidDirectoryName("1.")).toEqual(true); - expect(isValidDirectoryName("foo.")).toEqual(true); }); it("should return false for invalid directory names", function () { expect(isValidDirectoryName("")).toEqual(false); + expect(isValidDirectoryName("👨‍💻")).toEqual(false); expect(isValidDirectoryName("dir#")).toEqual(false); expect(isValidDirectoryName("dir!")).toEqual(false); expect(isValidDirectoryName("dir*")).toEqual(false); expect(isValidDirectoryName(".")).toEqual(false); expect(isValidDirectoryName("..")).toEqual(false); + expect(isValidDirectoryName("1.")).toEqual(false); + expect(isValidDirectoryName("foo.")).toEqual(false); }); });