35 lines
1.3 KiB
JavaScript
35 lines
1.3 KiB
JavaScript
const fs = require('fs');
|
|
const path = require('path');
|
|
|
|
(async () => {
|
|
const { escapeSmartHtml, decodeEntities } = await import('../web/src/htmlUtil.mjs');
|
|
|
|
const file = path.join(__dirname, '..', 'questions.json');
|
|
const data = JSON.parse(fs.readFileSync(file, 'utf8'));
|
|
let fixed = 0;
|
|
|
|
for (const set of data.sets) {
|
|
for (const q of set.questions) {
|
|
const nq = escapeSmartHtml(decodeEntities(q.q));
|
|
const nx = escapeSmartHtml(decodeEntities(q.exp || ''));
|
|
if (nq !== q.q) { q.q = nq; fixed++; }
|
|
if (nx !== q.exp) { q.exp = nx; fixed++; }
|
|
const no = q.opts.map(o => escapeSmartHtml(decodeEntities(o)));
|
|
if (JSON.stringify(no) !== JSON.stringify(q.opts)) { q.opts = no; fixed++; }
|
|
}
|
|
}
|
|
|
|
fs.writeFileSync(file, JSON.stringify(data, null, 2), 'utf8');
|
|
console.log('清洗完成,修正字段数:', fixed);
|
|
console.log('幂等检查(再跑一遍应无变化)...');
|
|
let again = 0;
|
|
for (const set of data.sets) {
|
|
for (const q of set.questions) {
|
|
if (escapeSmartHtml(decodeEntities(q.q)) !== q.q) again++;
|
|
if (escapeSmartHtml(decodeEntities(q.exp || '')) !== q.exp) again++;
|
|
if (JSON.stringify(q.opts.map(o => escapeSmartHtml(decodeEntities(o)))) !== JSON.stringify(q.opts)) again++;
|
|
}
|
|
}
|
|
console.log(again === 0 ? '幂等 ✓' : `仍会变化: ${again} 处 ✗`);
|
|
})();
|