diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index a9be3e6..430fe29 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -28,7 +28,7 @@ jobs: run: npx tsc -b --noEmit - name: ESLint - run: npx eslint src/ tests/ + run: npx eslint src/ tests/ e2e/ - name: Vitest 测试 run: npm test diff --git a/core/src/backup.rs b/core/src/backup.rs index b52cfde..8919b2a 100644 --- a/core/src/backup.rs +++ b/core/src/backup.rs @@ -19,7 +19,14 @@ pub fn get_appdata_dir() -> String { /// 在保存前调用,备份的是注册表中的当前值(保存前的状态) pub fn backup_registry(custom_dir: Option) -> Result { let backup_dir = match custom_dir { - Some(ref dir) if !dir.is_empty() => std::path::PathBuf::from(dir), + Some(ref dir) if !dir.is_empty() => { + let p = std::path::PathBuf::from(dir); + let normalized = dir.replace('/', "\\").to_lowercase(); + if normalized.starts_with("c:\\windows\\") || normalized.starts_with("c:\\program files\\") { + return Err("不允许备份到系统目录".into()); + } + p + } _ => backup_base_dir(), }; diff --git a/e2e/global.d.ts b/e2e/global.d.ts new file mode 100644 index 0000000..ce2d538 --- /dev/null +++ b/e2e/global.d.ts @@ -0,0 +1,5 @@ +interface Window { + __TAURI_INTERNALS__?: { + invoke: (cmd: string, args?: Record) => Promise; + }; +} diff --git a/e2e/tests/search-clean.spec.ts b/e2e/tests/search-clean.spec.ts index 50da331..b703d11 100644 --- a/e2e/tests/search-clean.spec.ts +++ b/e2e/tests/search-clean.spec.ts @@ -3,8 +3,7 @@ import { test, expect } from '@playwright/test'; test.beforeEach(async ({ page }) => { await page.addInitScript(() => { window.__TAURI_INTERNALS__ = { - // eslint-disable-next-line @typescript-eslint/no-unused-vars - invoke: async (cmd, args) => { + invoke: async (cmd, _args) => { switch (cmd) { case 'check_admin': return true; case 'load_system_paths': return ['C:\\\\Windows', 'invalid_path', 'C:\\\\Temp']; diff --git a/package.json b/package.json index 5aa86ad..dfee81f 100644 --- a/package.json +++ b/package.json @@ -7,6 +7,8 @@ "dev": "vite", "build": "tsc -b && vite build", "lint": "eslint .", + "lint:fix": "eslint . --fix", + "format": "cargo fmt", "preview": "vite preview", "test": "vitest run", "test:watch": "vitest", diff --git a/tsconfig.test.json b/tsconfig.test.json index 2c4a96c..8351320 100644 --- a/tsconfig.test.json +++ b/tsconfig.test.json @@ -4,5 +4,5 @@ "tsBuildInfoFile": "./node_modules/.tmp/tsconfig.test.tsbuildinfo", "types": ["vite/client", "vitest/globals"] }, - "include": ["src", "tests"] + "include": ["src", "tests", "e2e"] }