mirror of
https://github.com/bitburner-official/bitburner-src.git
synced 2024-12-20 21:25:47 +01:00
Blacklist some more special characters
Also improved readability of the valid character section by using escapeRegExp
This commit is contained in:
parent
8f684fa74c
commit
802f2f1c66
@ -1,6 +1,7 @@
|
|||||||
import { allContentFiles } from "./ContentFile";
|
import { allContentFiles } from "./ContentFile";
|
||||||
import type { BaseServer } from "../Server/BaseServer";
|
import type { BaseServer } from "../Server/BaseServer";
|
||||||
import type { FilePath } from "./FilePath";
|
import type { FilePath } from "./FilePath";
|
||||||
|
import { escapeRegExp } from "lodash";
|
||||||
|
|
||||||
/** The directory part of a BasicFilePath. Everything up to and including the last /
|
/** The directory part of a BasicFilePath. Everything up to and including the last /
|
||||||
* e.g. "file.js" => "", or "dir/file.js" => "dir/", or "../test.js" => "../" */
|
* e.g. "file.js" => "", or "dir/file.js" => "dir/", or "../test.js" => "../" */
|
||||||
@ -14,12 +15,20 @@ export type AbsolutePath = string & { __absolutePath: true };
|
|||||||
export type Directory = BasicDirectory & AbsolutePath;
|
export type Directory = BasicDirectory & AbsolutePath;
|
||||||
export const root = "" as Directory;
|
export const root = "" as Directory;
|
||||||
|
|
||||||
/** Regex string for a single valid path character. Invalid characters:
|
/** Invalid characters in actual filepaths and directory names:
|
||||||
* /: Invalid because it is the directory separator. It's allowed in the directory part, but only as the separator.
|
* /: Invalid because it is the directory separator. It's allowed in the directory part, but only as the separator.
|
||||||
* *, ?, [, and ]: Invalid in actual paths because they are used for globbing.
|
* *, ?, [, and ]: Invalid in actual paths because they are used for globbing.
|
||||||
|
* !: Invalid because it conflicts with terminal history fetching
|
||||||
* \: Invalid to avoid confusion with an escape character
|
* \: Invalid to avoid confusion with an escape character
|
||||||
|
* ~: Invalid because it might have a use in the terminal in the future.
|
||||||
|
* |: Invalid because it might have a use in the terminal in the future.
|
||||||
|
* #: Invalid because it might have a use in the terminal in the future.
|
||||||
|
* (quote marks): Invalid to avoid conflict with quote marks used in the terminal.
|
||||||
* (space): Invalid to avoid confusion with terminal command separator */
|
* (space): Invalid to avoid confusion with terminal command separator */
|
||||||
export const oneValidCharacter = "[^\\\\\\/* ?\\[\\]]";
|
const invalidCharacters = ["/", "*", "?", "[", "]", "!", "\\", "~", "|", "#", '"', "'", " "];
|
||||||
|
|
||||||
|
/** A valid character is any character that is not one of the invalid characters */
|
||||||
|
export const oneValidCharacter = `[^${escapeRegExp(invalidCharacters.join(""))}]`;
|
||||||
|
|
||||||
/** Regex string for matching the directory part of a valid filepath */
|
/** Regex string for matching the directory part of a valid filepath */
|
||||||
export const directoryRegexString = `^(?<directory>(?:${oneValidCharacter}+\\\/)*)`;
|
export const directoryRegexString = `^(?<directory>(?:${oneValidCharacter}+\\\/)*)`;
|
||||||
|
Loading…
Reference in New Issue
Block a user