@ondevplann/remotetype 0.2.0 → 0.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/bin/index.js +13 -2
- package/lib/sanitize.js +6 -2
- package/package.json +1 -1
package/bin/index.js
CHANGED
|
@@ -274,8 +274,14 @@ async function cmdServe(cfg) {
|
|
|
274
274
|
}
|
|
275
275
|
|
|
276
276
|
// type:常规文本注入(serve 与 relay 共用,relay 的 text 是 diff 出的增量)
|
|
277
|
-
//
|
|
278
|
-
|
|
277
|
+
// 二次预处理:即便上游已过滤,这里仍是最后一道防线。
|
|
278
|
+
// 对齐模式保留纯空白:换行/空格是手机输入框的真实内容(IME 自动插入的
|
|
279
|
+
// 换行不该被判失败挂起整批计划),见 sanitize 的 keepWhitespace。
|
|
280
|
+
const isAlignSource = meta.source === 'align';
|
|
281
|
+
const cleaned = sanitize(item.text, {
|
|
282
|
+
maxLength: cfg.maxTextLength,
|
|
283
|
+
keepWhitespace: isAlignSource,
|
|
284
|
+
});
|
|
279
285
|
if (!cleaned.ok) {
|
|
280
286
|
logger.warn('文本预处理后丢弃', { reason: cleaned.reason, clientId: item.clientId });
|
|
281
287
|
if (meta.source === 'align' && item.seq !== undefined) failedAlignSeqs.add(item.seq);
|
|
@@ -289,6 +295,11 @@ async function cmdServe(cfg) {
|
|
|
289
295
|
});
|
|
290
296
|
return;
|
|
291
297
|
}
|
|
298
|
+
if (isAlignSource && cleaned.text.length === 0) {
|
|
299
|
+
// 整条只含不可见字符:无可注入内容,也不算失败——commit 仍会推进 mirror
|
|
300
|
+
logger.debug('对齐空操作(仅不可见字符),跳过注入', { seq: item.seq });
|
|
301
|
+
return;
|
|
302
|
+
}
|
|
292
303
|
if (cleaned.truncated) {
|
|
293
304
|
logger.warn('文本超长已截断', {
|
|
294
305
|
originalLength: cleaned.originalLength,
|
package/lib/sanitize.js
CHANGED
|
@@ -32,10 +32,14 @@ function isInvisible(c) {
|
|
|
32
32
|
* @param {string} raw
|
|
33
33
|
* @param {object} [opts]
|
|
34
34
|
* @param {number} [opts.maxLength]
|
|
35
|
+
* @param {boolean} [opts.keepWhitespace] 保留纯空白文本(对齐模式用:
|
|
36
|
+
* 换行/空格是手机输入框的真实内容,整条空白不算「空文本」;
|
|
37
|
+
* 返回 ok:true 且 text 可能为空串,由调用方决定是否为无操作)
|
|
35
38
|
* @returns {{ok:boolean, text:string, reason?:string, truncated?:boolean, originalLength?:number}}
|
|
36
39
|
*/
|
|
37
40
|
function sanitize(raw, opts = {}) {
|
|
38
41
|
const maxLength = opts.maxLength ?? DEFAULT_MAX_LENGTH;
|
|
42
|
+
const keepWhitespace = opts.keepWhitespace === true;
|
|
39
43
|
|
|
40
44
|
if (typeof raw !== 'string') {
|
|
41
45
|
return { ok: false, text: '', reason: 'not_a_string' };
|
|
@@ -52,8 +56,8 @@ function sanitize(raw, opts = {}) {
|
|
|
52
56
|
// 2) 统一换行,避免 \r\n 造成目标程序出现多余字符
|
|
53
57
|
text = text.replace(/\r\n?/g, '\n');
|
|
54
58
|
|
|
55
|
-
// 3)
|
|
56
|
-
if (text.trim().length === 0) {
|
|
59
|
+
// 3) 空文本丢弃(keepWhitespace 时跳过:空白是对齐语义下的有效内容)
|
|
60
|
+
if (!keepWhitespace && text.trim().length === 0) {
|
|
57
61
|
return { ok: false, text: '', reason: 'empty_after_clean', originalLength };
|
|
58
62
|
}
|
|
59
63
|
|