Skip to content

Commit

Permalink
fix: import a plugin from manifest.json. Closes #358
Browse files Browse the repository at this point in the history
  • Loading branch information
ChugunovRoman committed Jan 15, 2024
1 parent 21a518c commit 90e360b
Show file tree
Hide file tree
Showing 2 changed files with 2 additions and 18 deletions.
5 changes: 2 additions & 3 deletions src/main/ExtensionManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import { dialogs } from "./Dialogs";
import { storage } from "Storage";
import { logger } from "./Logger";
import { FILE_EXTENSION_WHITE_LIST, FILE_WHITE_LIST, MANIFEST_FILE_NAME } from "Const";
import { ALLOW_CODE_FILES, ALLOW_EXT_FILES, ALLOW_UI_FILES, sanitizeFileName } from "Utils/Common";
import { ALLOW_CODE_FILES, ALLOW_EXT_FILES, ALLOW_UI_FILES } from "Utils/Common";
import { access, mkPath } from "Utils/Main";

type ObserverCallback = (args: any) => void;
Expand Down Expand Up @@ -438,8 +438,7 @@ export default class ExtensionManager {
if (
!FILE_WHITE_LIST.includes(file.name) &&
(!FILE_EXTENSION_WHITE_LIST.includes(extname(file.name)) ||
!/^[\w/]+(?:\.\w+)*\.\w+/.test(file.name) ||
file.name !== sanitizeFileName(file.name))
!/^[\w/]+(?:\.\w+)*\.\w+/.test(file.name))
) {
throw new Error(`Filename "${file.name}" not allowed`);
}
Expand Down
15 changes: 0 additions & 15 deletions src/utils/Common/extensions.ts
Original file line number Diff line number Diff line change
@@ -1,18 +1,3 @@
export const ALLOW_EXT_FILES = /^(.+\.(html|js|ts)|manifest.json)$/;
export const ALLOW_CODE_FILES = /^(.+\.(js|ts))$/;
export const ALLOW_UI_FILES = /^(.+\.html)$/;

export function sanitizeFileName(input: string): string {
const illegalRe = /[\/\?<>\\:\*\|":]/g;
const controlRe = /[\x00-\x1f\x80-\x9f]/g;
const reservedRe = /^\.+$/;
const windowsReservedRe = /^(con|prn|aux|nul|com[0-9]|lpt[0-9])(\..*)?$/i;
const windowsTrailingRe = /[\. ]+$/;

return input
.replace(illegalRe, "")
.replace(controlRe, "")
.replace(reservedRe, "")
.replace(windowsReservedRe, "")
.replace(windowsTrailingRe, "");
}

0 comments on commit 90e360b

Please sign in to comment.