fix(lanzou): remove JavaScript comments from response data (#8386)

* feat(lanzou): add RemoveJSComment function to clean JavaScript comments from HTML

* feat(lanzou): remove comments from share page data in getFilesByShareUrl function

* fix(lanzou): optimize RemoveJSComment function to improve comment removal logic
pull/8417/head
MadDogOwner 2025-04-19 14:24:43 +08:00 committed by GitHub
parent 28e5b5759e
commit 52d4e8ec47
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
2 changed files with 40 additions and 0 deletions

View File

@ -78,6 +78,42 @@ func RemoveNotes(html string) string {
})
}
// 清理JS注释
func RemoveJSComment(data string) string {
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后放入页面后再重新访问页面才能获得正常页面

View File

@ -348,6 +348,10 @@ func (d *LanZou) getFilesByShareUrl(shareID, pwd string, sharePageData string) (
file FileOrFolderByShareUrl
)
// 删除注释
sharePageData = RemoveNotes(sharePageData)
sharePageData = RemoveJSComment(sharePageData)
// 需要密码
if strings.Contains(sharePageData, "pwdload") || strings.Contains(sharePageData, "passwddiv") {
sharePageData, err := getJSFunctionByName(sharePageData, "down_p")