mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-20 05:05:47 +01:00
Merge pull request #3653 from Dane-Horn/3651-valid-folder-names-are-not-valid
TERMINAL: FIX #3651 Make directory name regex more flexible
This commit is contained in:
commit
18cb1bd4f9
@ -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 = /^.?[a-zA-Z0-9_-]+$/;
|
||||
// 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;
|
||||
|
@ -102,17 +102,28 @@ describe("Terminal Directory Tests", function () {
|
||||
expect(isValidDirectoryName(".a1")).toEqual(true);
|
||||
expect(isValidDirectoryName("._foo")).toEqual(true);
|
||||
expect(isValidDirectoryName("_foo")).toEqual(true);
|
||||
expect(isValidDirectoryName("foo.dir")).toEqual(true);
|
||||
expect(isValidDirectoryName("foov1.0.0.1")).toEqual(true);
|
||||
expect(isValidDirectoryName("foov1..0..0..1")).toEqual(true);
|
||||
expect(isValidDirectoryName("foov1-0-0-1")).toEqual(true);
|
||||
expect(isValidDirectoryName("foov1-0-0-1-")).toEqual(true);
|
||||
expect(isValidDirectoryName("foov1--0--0--1--")).toEqual(true);
|
||||
expect(isValidDirectoryName("foov1_0_0_1")).toEqual(true);
|
||||
expect(isValidDirectoryName("foov1_0_0_1_")).toEqual(true);
|
||||
expect(isValidDirectoryName("foov1__0__0__1")).toEqual(true);
|
||||
});
|
||||
|
||||
it("should return false for invalid directory names", function () {
|
||||
expect(isValidDirectoryName("")).toEqual(false);
|
||||
expect(isValidDirectoryName("foo.dir")).toEqual(false);
|
||||
expect(isValidDirectoryName("1.")).toEqual(false);
|
||||
expect(isValidDirectoryName("foo.")).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);
|
||||
expect(isValidDirectoryName("foov1.0.0.1.")).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user