fix(modal): restrict confirmText length to 4 chars and safeguard banner null access

这个提交包含在:
xcbyy
2026-10-13 08:50:20 +08:00
父节点 6e78a7e4b7
当前提交 a004584109
共有 3 个文件被更改,包括 72 次插入 和 11 次删除

查看文件

@@ -408,6 +408,51 @@ describe('ContentSecurityService & Compliance Architecture (TDD 微信内容安
expect(content).toContain('onWechatChooseAvatar');
});
it('全端 uni.showModal 按钮文字长度严禁超过 4 个汉字 (符合微信官方标准,防止弹窗崩溃)', () => {
const walk = (dir: string) => {
const files = fs.readdirSync(dir);
for (const f of files) {
const full = path.join(dir, f);
if (f === 'node_modules' || f === 'dist' || f === 'unpackage' || f === '.git') continue;
if (fs.statSync(full).isDirectory()) {
walk(full);
} else if (f.endsWith('.vue') || f.endsWith('.js') || f.endsWith('.ts')) {
const content = fs.readFileSync(full, 'utf-8');
const modalRegex = /showModal\s*\(\s*\{([\s\S]*?)\}\s*\)/g;
let match;
while ((match = modalRegex.exec(content)) !== null) {
const modalBody = match[1];
const confirmMatch = modalBody.match(/confirmText\s*:\s*['"`]([^'"`]+)['"`]/);
if (confirmMatch && confirmMatch[1].length > 4) {
throw new Error(`Oversized confirmText in ${path.relative(rootDir, full)}: "${confirmMatch[1]}"`);
}
const cancelMatch = modalBody.match(/cancelText\s*:\s*['"`]([^'"`]+)['"`]/);
if (cancelMatch && cancelMatch[1].length > 4) {
throw new Error(`Oversized cancelText in ${path.relative(rootDir, full)}: "${cancelMatch[1]}"`);
}
}
}
}
};
walk(path.join(rootDir, 'pwuniapp'));
});
it('推广赚钱二级分销弹窗必须符合微信4字规范并支持一键复制专属邀请码', () => {
const userIndexPath = path.join(rootDir, 'pwuniapp', 'pages', 'user', 'index.vue');
const content = fs.readFileSync(userIndexPath, 'utf-8');
expect(content).toContain('showInvitePoster');
expect(content).toContain('一键复制');
expect(content).toContain('setClipboardData');
});
it('首页 Banner 轮播必须具备防 null 链式安全访问与数据容错过滤', () => {
const indexVuePath = path.join(rootDir, 'pwuniapp', 'pages', 'index', 'index.vue');
const content = fs.readFileSync(indexVuePath, 'utf-8');
expect(content).toContain('banner?.bg');
expect(content).toContain('banner?.image');
expect(content).toContain('banners.value = list.filter(b => b && typeof b === \'object\');');
});
it('所有个人中心改造代码严禁包含任何系统 Emoji', () => {
const userIndexPath = path.join(rootDir, 'pwuniapp', 'pages', 'user', 'index.vue');
const text = fs.readFileSync(userIndexPath, 'utf-8');