Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/pkg/utils/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -427,7 +427,6 @@ describe.concurrent("checkSilenceUpdate", () => {

describe.concurrent("cleanFileName", () => {
it.concurrent("should replace illegal characters with dashes", () => {
expect(cleanFileName("file/name")).toBe("file-name");
expect(cleanFileName("file\\name")).toBe("file-name");
expect(cleanFileName("file:name")).toBe("file-name");
expect(cleanFileName("file*name")).toBe("file-name");
Expand All @@ -443,6 +442,7 @@ describe.concurrent("cleanFileName", () => {

it.concurrent("should handle valid filename", () => {
expect(cleanFileName("valid_file.txt")).toBe("valid_file.txt");
expect(cleanFileName("file/name.txt")).toBe("file/name.txt");
});
});

Expand Down
10 changes: 8 additions & 2 deletions src/pkg/utils/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -396,8 +396,14 @@ export function toCamelCase(key: SystemConfigKey) {
}

export function cleanFileName(name: string): string {
// eslint-disable-next-line no-control-regex, no-useless-escape
return name.replace(/[\x00-\x1F\\\/:*?"<>|]+/g, "-").trim();
// https://github.com/Tampermonkey/tampermonkey/issues/2413
// https://developer.chrome.com/docs/extensions/reference/api/downloads#type-DownloadOptions
// A file path relative to the Downloads directory to contain the downloaded file, possibly containing subdirectories.
// Absolute paths, empty paths, and paths containing back-references ".." will cause an error.
let n = name;
// eslint-disable-next-line no-control-regex
n = n.replace(/[\x00-\x1F\\:*?"<>|]+/g, "-");
return n.replace(/\.\.+/g, "-").trim();
}

export const sourceMapTo = (scriptName: string) => {
Expand Down
Loading