-
-
Notifications
You must be signed in to change notification settings - Fork 6.7k
fix(lanzou): remove JavaScript comments from response data #8386
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
WalkthroughThis PR enhances the cleaning of HTML content comments in the Changes
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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. |
@@ -78,6 +78,42 @@ func RemoveNotes(html string) string { | |||
}) | |||
} | |||
|
|||
// 清理JS注释 | |||
func RemoveJSComment(data string) string { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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.
Copilot uses AI. Check for mistakes.
// 删除注释 | ||
sharePageData = RemoveNotes(sharePageData) | ||
sharePageData = RemoveJSComment(sharePageData) | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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") | |
} |
Copilot uses AI. Check for mistakes.
@xrgzs 新增加的RemoveJSComment函数中对于块注释处理有问题,把块注释打开了,里面内容没有清理掉,导致块注释中的代码影响到了函数的解析,需要在匹配到块注释结束标志前,跳过注释内容的写入 |
Close: #8286
Close: #8351
getFilesByShareUrl()
中增强对 HTML 内容注释的清洗RemoveJSComment()
方法,尝试对 JavaScript 注释进行解析并清理findJSFunctionIndex()
方法找到down_p
函数后无法正确解析反括号,导致无法读取参数,报错failed link: failed get link: not find down_p function
getJSFunctionByName()
方法获取到被注释的错误信息,被误导使用错误的参数请求,从而返回 405 “文件不存在,或者已被删除”页面