mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-11-17 21:23:54 +01:00
adjust regex for directory name
new regex allows for more flexible folder names, while still disallowing '.' and '..'
This commit is contained in:
parent
0121fee6e4
commit
0988ec8226
@ -51,7 +51,7 @@ export function isValidFilename(filename: string): boolean {
|
||||
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_-]+$/;
|
||||
const regex = /^\.?(?:\w[_\-.%]*)+$/;
|
||||
|
||||
// match() returns null if no match is found
|
||||
return name.match(regex) != null;
|
||||
|
@ -102,17 +102,18 @@ 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("1.")).toEqual(true);
|
||||
expect(isValidDirectoryName("foo.")).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("dir#")).toEqual(false);
|
||||
expect(isValidDirectoryName("dir!")).toEqual(false);
|
||||
expect(isValidDirectoryName("dir*")).toEqual(false);
|
||||
expect(isValidDirectoryName(".")).toEqual(false);
|
||||
expect(isValidDirectoryName("..")).toEqual(false);
|
||||
});
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user