fix(lanzou): remove JavaScript comments from response data#8386
fix(lanzou): remove JavaScript comments from response data#8386xhofe merged 3 commits intoAlistGo:mainfrom
Conversation
WalkthroughThis PR enhances the cleaning of HTML content comments in the Changes
|
There was a problem hiding this comment.
Pull Request Overview
This PR enhances the processing of response data by removing HTML and JavaScript comments to avoid mis-parsed data issues. Key changes include:
- Cleaning HTML comments with RemoveNotes and JavaScript comments with a new RemoveJSComment function in getFilesByShareUrl.
- Adding the RemoveJSComment utility in help.go to strip out both single-line and multi-line JS comments.
Reviewed Changes
Copilot reviewed 2 out of 2 changed files in this pull request and generated 2 comments.
| File | Description |
|---|---|
| drivers/lanzou/util.go | Invokes new comment removal functions to improve share data parsing. |
| drivers/lanzou/help.go | Introduces RemoveJSComment for parsing and stripping out JS comments. |
| } | ||
|
|
||
| // 清理JS注释 | ||
| func RemoveJSComment(data string) string { |
There was a problem hiding this comment.
The RemoveJSComment function does not account for JavaScript string literals, which might contain sequences resembling comment markers. This could lead to unintended removal of valid data; consider adding checks to skip over string contents.
| // 删除注释 | ||
| sharePageData = RemoveNotes(sharePageData) | ||
| sharePageData = RemoveJSComment(sharePageData) | ||
|
|
There was a problem hiding this comment.
Verify that sequential use of RemoveNotes followed by RemoveJSComment does not inadvertently remove non-comment text. Clarify the separation of concerns between HTML comment removal and JS comment removal.
| // 删除注释 | |
| sharePageData = RemoveNotes(sharePageData) | |
| sharePageData = RemoveJSComment(sharePageData) | |
| // 删除注释 | |
| // Remove HTML comments | |
| sharePageData = RemoveNotes(sharePageData) | |
| // Remove JavaScript comments | |
| sharePageData = RemoveJSComment(sharePageData) | |
| // Validate that no non-comment text was removed | |
| if strings.Contains(sharePageData, "<!--") || strings.Contains(sharePageData, "//") { | |
| return nil, fmt.Errorf("unexpected removal of non-comment text in sharePageData") | |
| } |
|
@xrgzs 新增加的RemoveJSComment函数中对于块注释处理有问题,把块注释打开了,里面内容没有清理掉,导致块注释中的代码影响到了函数的解析,需要在匹配到块注释结束标志前,跳过注释内容的写入 |

Close: #8286
Close: #8351
getFilesByShareUrl()中增强对 HTML 内容注释的清洗RemoveJSComment()方法,尝试对 JavaScript 注释进行解析并清理findJSFunctionIndex()方法找到down_p函数后无法正确解析反括号,导致无法读取参数,报错failed link: failed get link: not find down_p functiongetJSFunctionByName()方法获取到被注释的错误信息,被误导使用错误的参数请求,从而返回 405 “文件不存在,或者已被删除”页面