8000 fix(lanzou): remove JavaScript comments from response data by xrgzs · Pull Request #8386 · AlistGo/alist · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

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

Merged
merged 3 commits into from
Apr 19, 2025

Conversation

xrgzs
Copy link
Contributor
@xrgzs xrgzs commented Apr 15, 2025

Close: #8286
Close: #8351

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

Copy link

Walkthrough

This PR enhances the cleaning of HTML content comments in the getFilesByShareUrl() function by adding a new method RemoveJSComment(). This method attempts to parse and clean JavaScript comments to prevent issues caused by various JavaScript comments that lead to errors in parsing functions and incorrect parameter usage.

Changes

File Summary
drivers/lanzou/help.go Added RemoveJSComment() function to clean JavaScript comments from data.
drivers/lanzou/util.go Integrated RemoveJSComment() to clean comments from sharePageData.

@xhofe xhofe requested a review from Copilot April 19, 2025 06:23
Copy link
Contributor
@Copilot Copilot AI left a 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 {
Copy link
Preview
Copilot AI Apr 19, 2025

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.

Comment on lines +351 to +354
// 删除注释
sharePageData = RemoveNotes(sharePageData)
sharePageData = RemoveJSComment(sharePageData)

Copy link
Preview
Copilot AI Apr 19, 2025

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.

Suggested change
// 删除注释
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.

@xhofe xhofe merged commit 52d4e8e into AlistGo:main Apr 19, 2025
12 checks passed
@xrgzs xrgzs deleted the fix/lanzou-pswd-share branch April 19, 2025 08:05
@410680876f1
Copy link

@xrgzs 新增加的RemoveJSComment函数中对于块注释处理有问题,把块注释打开了,里面内容没有清理掉,导致块注释中的代码影响到了函数的解析,需要在匹配到块注释结束标志前,跳过注释内容的写入
PixPin_2025-04-30_11-19-33

@xrgzs xrgzs restored the fix/lanzou-pswd-share branch April 30, 2025 05:39
@xrgzs xrgzs deleted the fix/lanzou-pswd-share branch April 30, 2025 06:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
3 participants
0