Skip to content

Commit c335374

Browse files
committed
fix(build): sanitize command names to avoid hidden-char path errors
1 parent fa80955 commit c335374

3 files changed

Lines changed: 23 additions & 3 deletions

File tree

dist/data.json

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1279,6 +1279,11 @@
12791279
"p": "/killall",
12801280
"d": "使用进程的名称来杀死一组进程"
12811281
},
1282+
"l2ping": {
1283+
"n": "l2ping",
1284+
"p": "/l2ping",
1285+
"d": "收发 L2CAP 回显请求,用于检查与目标蓝牙设备的连通性。"
1286+
},
12821287
"last": {
12831288
"n": "last",
12841289
"p": "/last",
@@ -1779,6 +1784,11 @@
17791784
"p": "/nmcli",
17801785
"d": "地址配置工具"
17811786
},
1787+
"nmtui": {
1788+
"n": "nmtui",
1789+
"p": "/nmtui",
1790+
"d": "基于文本的用户界面(TUI),用于控制和配置 NetworkManager。"
1791+
},
17821792
"nohup": {
17831793
"n": "nohup",
17841794
"p": "/nohup",

dist/data.min.json

Lines changed: 1 addition & 1 deletion
Large diffs are not rendered by default.

scripts/build.mjs

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,13 @@ const dataJsonMinPath = path.resolve(process.cwd(), 'dist', 'data.min.json');
1414
const cssPath = path.resolve(deployDir, 'css', 'index.css');
1515
const contributorsPath = path.resolve(process.cwd(), 'CONTRIBUTORS.svg');
1616

17+
function sanitizeCommandName(value) {
18+
return String(value || '')
19+
.replace(/^\uFEFF/, '')
20+
.replace(/[\u200B-\u200D\u2060]/g, '')
21+
.trim();
22+
}
23+
1724
;(async () => {
1825
try {
1926
await FS.ensureDir(deployDir);
@@ -151,6 +158,7 @@ const contributorsPath = path.resolve(process.cwd(), 'CONTRIBUTORS.svg');
151158
let title = str.match(/[^===]+(?=[===])/g);
152159
title = title[0] ? title[0].replace(/\n/g, '') : title[0];
153160
title = title.replace(/\r/, '')
161+
title = sanitizeCommandName(title)
154162
// 命令名称
155163
json["n"] = title;
156164
// 命令路径
@@ -186,13 +194,15 @@ const contributorsPath = path.resolve(process.cwd(), 'CONTRIBUTORS.svg');
186194
const current_path = toPath.replace(new RegExp(`${deployDir}`), '');
187195
const tmpStr = await FS.readFile(fromPath);
188196
let mdPathName = '';
197+
let mdFileName = '';
189198
let mdhtml = '';
190199
let relative_path = '';
191200
if (mdPath) {
192201
// CSS/JS 引用相对地址
193202
relative_path = '../';
194-
mdPathName = `/command/${desJson.n}.md`;
195-
const READMESTR = await FS.readFile(path.resolve(mdPath, `${desJson.n}.md`));
203+
mdFileName = (desJson.p ? String(desJson.p).replace(/^\//, '') : sanitizeCommandName(desJson.n));
204+
mdPathName = `/command/${mdFileName}.md`;
205+
const READMESTR = await FS.readFile(path.resolve(mdPath, `${mdFileName}.md`));
196206
mdhtml = await markdownToHTML(READMESTR.toString());
197207
}
198208
// 生成 HTML

0 commit comments

Comments
 (0)