Skip to content

JiuwenSwarm is an intelligent AI Agent built on openJiuwen. It extends the powerful capabilities of large language models directly to your fingertips through various communication apps you use daily.

Python

fix(skill_turbo): PPT生成收窄畸形开标签引号内判定,放行标签形态文本的合法属性值

CodehubTTG7e8669c8f311
diff --git a/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/ppt_page_gen.py b/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/ppt_page_gen.py
index 925b4bc8e7..9ee305ccae 100644
--- a/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/ppt_page_gen.py
+++ b/jiuwenswarm/server/runtime/skill_turbo/skill_codes/ppt/ppt_page_gen.py
@@ -2257,8 +2257,14 @@ def _has_malformed_open_tag(html: str) -> bool:
直接跳到 ``</name`` 闭合前缀;缺闭合(如截断的 ``<script>var a=1``)
判畸形(剩余文档全部被吞)。自闭合 ``<script/>`` 不开 raw text
(htmlparser2 stateInSelfClosingTag 将 isSpecial 置回 false);
- - 引号区间内出现 ``<``+ASCII 字母/斜杠时,仅当区间内还含 ``>``(吞入
- 了完整标签)或引号到文件尾仍未闭合时才判畸形;
+ - 引号区间内出现 ``<``+ASCII 字母/斜杠时,仅当引号角色混淆(从 ``<``
+ 到下一个引号的区间含 ``>`` 且以 ``=`` 结尾——区间含 ``>`` 说明值已
+ 吞入完整标签,区间以 ``=`` 结尾说明该"闭合引号"实为下一属性的开
+ 引号,本属性值的真正闭合被吞,后续标签会从解析树消失)或引号到
+ 文件尾仍未闭合时才判畸形;仅含 ``>`` 的标签形态文本(如
+ ``title="支持 <b> 标记"``)与仅以 ``=`` 结尾的字面值(如
+ ``data-formula="若a<b则x="``)均是 htmlparser2 的合法字面属性值,
+ 不得误杀;
- 标签引号外出现 ``<``+ASCII 字母/斜杠(如 ``<div class="a" <span>``)
判畸形:``<span`` 被吞成属性名,真实标签从解析树消失;
- 注释/声明/处理指令内容对解析器不透明,跳到 ``-->`` / ``>``;未闭合
@@ -2309,8 +2315,15 @@ def _has_malformed_open_tag(html: str) -> bool:
in_quote = None
elif ch == "<" and (_is_ascii_alpha(next_ch) or next_ch == "/"):
closing = html.find(in_quote, pos + 1)
- if closing == -1 or ">" in html[pos:closing]:
- # 引号吞入了完整标签,或引号到文件尾未闭合
+ if closing == -1:
+ # 引号到文件尾未闭合
+ return True
+ segment = html[pos:closing]
+ if ">" in segment and segment.rstrip().endswith("="):
+ # 双签名:区间含 ">"(值已吞入完整标签)且以 "="
+ # 结尾(找到的"闭合引号"实为下一属性的开引号,
+ # 本属性值的真正闭合被吞)。仅含 ">" 的标签形态
+ # 文本或仅以 "=" 结尾的字面值均按合法放行
return True
else:
if ch == '"' or ch == "'":
diff --git a/tests/unit_tests/server/runtime/skill_turbo/test_ppt_backup_selfheal.py b/tests/unit_tests/server/runtime/skill_turbo/test_ppt_backup_selfheal.py
index 5dcc4d31b3..1e06f45132 100644
--- a/tests/unit_tests/server/runtime/skill_turbo/test_ppt_backup_selfheal.py
+++ b/tests/unit_tests/server/runtime/skill_turbo/test_ppt_backup_selfheal.py
@@ -176,6 +176,15 @@ def test_has_malformed_open_tag_detects_incident_pattern():
assert _has_malformed_open_tag('<div class="a') is True
# 引号吞入下一个标签开头(跨标签吞没)
assert _has_malformed_open_tag('<div class="outer<span class="x">y</span>') is True
+ # 引号角色混淆:级联引号错位后第三个引号吞到文件尾(tag-to-EOF 路径)
+ assert _has_malformed_open_tag('<div title="a <b class="x">hi</div>') is True
+ # 引号角色混淆双签名:区间含 ">" 且以 "=" 结尾(值吞入完整标签后撞上
+ # 下一属性的开引号,本属性值的真正闭合被吞)
+ assert _has_malformed_open_tag(
+ '<div title="a\n<span>hi</span> rest="v">x</div>'
+ ) is True
+ # 裸属性名后紧跟引号:引号吞入 ">" 后续到文件尾未闭合
+ assert _has_malformed_open_tag('<div title="a <b> c="v">y</div>') is True
# 引号已闭合但标签缺 ">":新标签被 htmlparser2 吞成属性名
assert _has_malformed_open_tag('<div class="a" <span>text</span></div>') is True
assert _has_malformed_open_tag('<div class="a" <span class="b">t</span></div>') is True
@@ -198,6 +207,15 @@ def test_has_malformed_open_tag_allows_legitimate_constructs():
"halfwidth lt in data attr": '<div data-trend="a<b and c">x</div>',
"halfwidth lt in onclick": '<div onclick="return a<b;">x</div>',
"halfwidth lt+gt in cn attr": '<div title="利润<支出>预算">x</div>',
+ "tag-like text in attr": '<div title="支持 <b> 标记">x</div>',
+ "tag-like alt": '<img alt="<logo>" src="a.png">',
+ "code in data attr": '<div data-code="a<b>c">x</div>',
+ "formula in data attr": '<div data-formula="若a<b则c>d">x</div>',
+ "eq-suffix formula in data attr": '<div data-formula="若a<b则x=">填空</div>',
+ "eq-suffix code attr with next attr": '<div data-code="a <b x=" data-note="n">t</div>',
+ "self-closing tag text in attr": '<div data-x="<br/>换行">x</div>',
+ "quoted value itself tag-like": '<div title="<b class=x>">y</div>',
+ "swallow-looking value then bare attr": '<div title="a <b>"x>y</div>',
"cn lt in body text": '<div class="slide"><p>利润<支出</p></div>',
"cn lt in body text 2": '<div>本季度收入<成本</div>',
"js lt in script raw text": '<script>for(i=0;i<n;i++){sum+=a[i]}</script>',