Develop (#25)
核心功能新增 工具套件扩展 JSON 工具(差异比较、格式化、转 YAML/TOML、压缩) Base64 转换器(文本/文件/图像编解码) Markdown ↔ HTML 双向转换 JWT 解析器 文本统计工具 二维码生成/解析(替换库以减小体积) 表单工具(已移除) 表单映射、智能填充、高亮定位功能已移除 架构与工程改进 技术栈升级 引入 @webext-core/messaging 重构消息通信 添加 @dnd-kit 支持功能列表拖拽排序 引入 i18next 实现中英文国际化 使用 MUI 主题系统替代硬编码样式,支持暗色模式 代码质量 统一组件导出为默认导出 提取公共组件(TextInputArea、SwitchButtonGroup、PageHeader、DecodeResultPaper) 使用 useStorageState 钩子统一管理存储状态 添加 PageErrorBoundary 页面级错误边界 实现组件懒加载优化首屏性能 关键重构 路由系统重构 — 支持独立标签页模式,合并路由与功能配置 状态管理优化 — 存储状态增加快照机制、验证器和防抖处理 剪贴板与打印工具 — 统一为 async/await 形式,修复重复触发问题 存储清理器 — 使用 TextEncoder 准确计算 UTF-8 字节数,支持 TB 单位 测试与 CI 测试覆盖 — 为新增工具、公共组件、边界场景补充单元测试 CI 精简 — 移除 Firefox 测试,仅保留 Chrome;修正类型检查命令
This commit is contained in:
@@ -77,6 +77,11 @@ describe('base64ToText', () => {
|
||||
expect(result).toBe('hello');
|
||||
});
|
||||
|
||||
it('应该处理带参数(如 charset)的 data URI 前缀', () => {
|
||||
const result = base64ToText('data:text/plain;charset=utf-8;base64,aGVsbG8=');
|
||||
expect(result).toBe('hello');
|
||||
});
|
||||
|
||||
it('应该剥离带空白的 data URI 前缀', () => {
|
||||
const result = base64ToText(' data:text/plain;base64,aGVsbG8= ');
|
||||
expect(result).toBe('hello');
|
||||
@@ -168,6 +173,13 @@ describe('extractMimeTypeFromDataUri', () => {
|
||||
expect(extractMimeTypeFromDataUri('data:text/plain;base64,SGVsbG8=')).toBe('text/plain');
|
||||
});
|
||||
|
||||
it('应该从带参数的 data URI 中提取 MIME 类型', () => {
|
||||
expect(extractMimeTypeFromDataUri('data:text/plain;charset=utf-8;base64,SGVsbG8=')).toBe(
|
||||
'text/plain',
|
||||
);
|
||||
expect(extractMimeTypeFromDataUri('data:image/svg+xml;base64,PHN2Zw==')).toBe('image/svg+xml');
|
||||
});
|
||||
|
||||
it('应该对无效的 data URI 返回默认类型', () => {
|
||||
expect(extractMimeTypeFromDataUri('invalid')).toBe('application/octet-stream');
|
||||
});
|
||||
@@ -333,6 +345,12 @@ describe('base64ToBlob', () => {
|
||||
expect(result.rawBase64).toBe('iVBORw0KGgo=');
|
||||
});
|
||||
|
||||
it('应该处理带参数的 data URI 前缀', () => {
|
||||
const result = base64ToBlob('data:text/plain;charset=utf-8;base64,aGVsbG8=');
|
||||
expect(result.rawBase64).toBe('aGVsbG8=');
|
||||
expect(result.mimeType).toBe('text/plain');
|
||||
});
|
||||
|
||||
it('blob 大小应该等于解码后的字节数', () => {
|
||||
const result = base64ToBlob('aGVsbG8=');
|
||||
expect(result.blob.size).toBe(5);
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
import { formatSize, isRestrictedUrl } from '@/utils/storageCleaner';
|
||||
import { clearCookies, formatSize, isRestrictedUrl } from '@/utils/storageCleaner';
|
||||
|
||||
describe('storageCleaner utils', () => {
|
||||
describe('isRestrictedUrl', () => {
|
||||
@@ -80,4 +80,54 @@ describe('storageCleaner utils', () => {
|
||||
expect(formatSize(1025)).toBe('1.0 KB');
|
||||
});
|
||||
});
|
||||
|
||||
describe('clearCookies', () => {
|
||||
it('should strip leading dot from cookie domain when removing cookies', async () => {
|
||||
const mockCookies = [
|
||||
{ name: 'session', domain: '.example.com', path: '/', secure: true, storeId: '0' },
|
||||
{ name: 'auth', domain: '.example.com', path: '/api', secure: false, storeId: '0' },
|
||||
];
|
||||
(chrome.cookies.getAll as any).mockResolvedValue(mockCookies);
|
||||
(chrome.cookies.remove as any).mockResolvedValue(undefined);
|
||||
|
||||
const result = await clearCookies('https://example.com');
|
||||
|
||||
expect(result).toEqual({ success: true, count: 2 });
|
||||
expect(chrome.cookies.remove).toHaveBeenCalledWith({
|
||||
url: 'https://example.com/',
|
||||
name: 'session',
|
||||
storeId: '0',
|
||||
});
|
||||
expect(chrome.cookies.remove).toHaveBeenCalledWith({
|
||||
url: 'http://example.com/api',
|
||||
name: 'auth',
|
||||
storeId: '0',
|
||||
});
|
||||
});
|
||||
|
||||
it('should handle domains without leading dot', async () => {
|
||||
const mockCookies = [
|
||||
{ name: 'pref', domain: 'sub.example.com', path: '/path', secure: true, storeId: '0' },
|
||||
];
|
||||
(chrome.cookies.getAll as any).mockResolvedValue(mockCookies);
|
||||
(chrome.cookies.remove as any).mockResolvedValue(undefined);
|
||||
|
||||
const result = await clearCookies('https://sub.example.com');
|
||||
|
||||
expect(result).toEqual({ success: true, count: 1 });
|
||||
expect(chrome.cookies.remove).toHaveBeenCalledWith({
|
||||
url: 'https://sub.example.com/path',
|
||||
name: 'pref',
|
||||
storeId: '0',
|
||||
});
|
||||
});
|
||||
|
||||
it('should return error when operation fails', async () => {
|
||||
(chrome.cookies.getAll as any).mockRejectedValue(new Error('Permission denied'));
|
||||
|
||||
const result = await clearCookies('https://example.com');
|
||||
|
||||
expect(result).toEqual({ success: false, error: 'Error: Permission denied' });
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -78,8 +78,8 @@ export function textToBase64(text: string): TextToBase64Result {
|
||||
};
|
||||
}
|
||||
|
||||
/** 匹配 data URI 的 base64 前缀,如 "data:image/png;base64," */
|
||||
const DATA_URI_BASE64_PREFIX = /^data:[^;,]+;base64,/i;
|
||||
/** 匹配 data URI 的 base64 前缀,如 "data:image/png;base64,"(允许中间含参数) */
|
||||
const DATA_URI_BASE64_PREFIX = /^data:[^,]+;base64,/i;
|
||||
|
||||
/**
|
||||
* 将 Base64 字符串解码为文本
|
||||
@@ -208,7 +208,7 @@ export function fileToBase64(file: File): Promise<FileToBase64Result> {
|
||||
* @returns MIME 类型
|
||||
*/
|
||||
export function extractMimeTypeFromDataUri(dataUri: string): string {
|
||||
const match = dataUri.match(/^data:([^;]+);base64,/);
|
||||
const match = dataUri.match(/^data:([^;,]+)[^,]*;base64,/);
|
||||
return match ? match[1] : 'application/octet-stream';
|
||||
}
|
||||
|
||||
|
||||
@@ -192,7 +192,8 @@ export async function clearCookies(url: string): Promise<StorageCleanResult> {
|
||||
const cookies = await chrome.cookies.getAll({ url });
|
||||
for (const cookie of cookies) {
|
||||
const protocol = cookie.secure ? 'https:' : 'http:';
|
||||
const cookieUrl = `${protocol}//${cookie.domain}${cookie.path}`;
|
||||
const domain = cookie.domain.startsWith('.') ? cookie.domain.slice(1) : cookie.domain;
|
||||
const cookieUrl = `${protocol}//${domain}${cookie.path}`;
|
||||
await chrome.cookies.remove({
|
||||
url: cookieUrl,
|
||||
name: cookie.name,
|
||||
|
||||
Reference in New Issue
Block a user