Feat/react framework - #36
Merged
Merged
Conversation
**问题根因**
在 markdown_processor_ast.js 的表格修复逻辑中:
1. 当数据行列数 < 分隔符列数时,while 循环尝试添加空单元格
2. 原逻辑:`fixedLine.slice(0, -1) + ' |'` 只是在末尾加空格,不增加管道符数量
3. 导致死循环,页面卡住无响应
**错误日志**
```
[MarkdownProcessorAST] 数据行列数不匹配:4 vs 13
(之后卡住)
```
**修复方案 (line 783-808)**
1️⃣ **修复死循环逻辑**
- 原代码:条件判断 `endsWith('|')` 后只加空格,不增加管道符
- 新逻辑:直接添加完整的空单元格 `|` + ` |`
- 确保每次迭代都增加管道符数量
2️⃣ **添加死循环保护**
- 最大迭代次数:100 次
- 超过限制时输出警告并使用原始行(降级处理)
3️⃣ **新增列数过多的处理**
- 当 `currPipes > sepPipes` 时,截断多余的列
- 使用 `split('|')` + `slice()` 保留正确数量的列
- 确保结尾有 `|`
**代码对比**
```javascript
// ❌ 原代码(死循环)
while (count < target) {
if (line.endsWith('|')) {
line = line.slice(0, -1) + ' |'; // 不增加管道符!
} else {
line += ' |';
}
}
// ✅ 新代码(正确)
while (count < target && iterations < 100) {
if (!line.endsWith('|')) {
line += '|'; // 先确保末尾有 |
}
line += ' |'; // 再添加新单元格
iterations++;
}
```
预期效果:表格列数不匹配时能正确修复,不再卡住
**新增保护措施**
1️⃣ **分隔符列数修复循环保护 (line 757-775)**
- 场景:表头列数多,分隔符列数少
- 原有逻辑:`while (count < target) { fixedSep += '---|'; }`
- 新增保护:
- 最大迭代 100 次
- 超限时警告并使用原始行
- 将日志移入成功分支
2️⃣ **表格行提取循环保护 (line 844-878)**
- 场景:从大段文本中提取多行表格数据
- 原有逻辑:`while (remaining.length > 0)`
- 新增保护:
- 最大迭代 10000 次(支持大文档)
- 检测无进展:`remaining.length >= previousLength` → 立即退出
- 记录前后长度变化确保循环有进展
**防护策略总结**
现已覆盖所有 3 个可能的死循环点:
1. ✅ 数据行列数修复(已修复)
2. ✅ 分隔符列数修复(本次新增)
3. ✅ 表格行提取(本次新增)
**安全机制**
- 计数器保护:限制最大迭代次数
- 进展检测:每次迭代必须减少剩余字符串长度
- 降级处理:超限时使用原始行或中断提取
- 详细日志:记录异常情况便于调试
预期效果:即使遇到极端格式错误的表格,也能安全退出不卡死
|
The latest updates on your projects. Learn more about Vercel for GitHub.
|
This branch was successfully deployed
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.