Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
36 changes: 36 additions & 0 deletions drivers/lanzou/help.go
Original file line number Diff line number Diff line change
Expand Up @@ -78,6 +78,42 @@ func RemoveNotes(html string) string {
})
}

// 清理JS注释
func RemoveJSComment(data string) string {
Copy link

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.
var result strings.Builder
inComment := false
inSingleLineComment := false

for i := 0; i < len(data); i++ {
v := data[i]

if inSingleLineComment && (v == '\n' || v == '\r') {
inSingleLineComment = false
result.WriteByte(v)
continue
}
if inComment && v == '*' && i+1 < len(data) && data[i+1] == '/' {
inComment = false
continue
}
if v == '/' && i+1 < len(data) {
nextChar := data[i+1]
if nextChar == '*' {
inComment = true
i++
continue
} else if nextChar == '/' {
inSingleLineComment = true
i++
continue
}
}
result.WriteByte(v)
}

return result.String()
}

var findAcwScV2Reg = regexp.MustCompile(`arg1='([0-9A-Z]+)'`)

// 在页面被过多访问或其他情况下,有时候会先返回一个加密的页面,其执行计算出一个acw_sc__v2后放入页面后再重新访问页面才能获得正常页面
Expand Down
4 changes: 4 additions & 0 deletions drivers/lanzou/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -348,6 +348,10 @@ func (d *LanZou) getFilesByShareUrl(shareID, pwd string, sharePageData string) (
file FileOrFolderByShareUrl
)

// 删除注释
sharePageData = RemoveNotes(sharePageData)
sharePageData = RemoveJSComment(sharePageData)

Comment on lines +351 to +354
Copy link

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.
// 需要密码
if strings.Contains(sharePageData, "pwdload") || strings.Contains(sharePageData, "passwddiv") {
sharePageData, err := getJSFunctionByName(sharePageData, "down_p")
Expand Down
Loading