Skip to content

Commit 52d4e8e

Browse files
authored
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
1 parent 28e5b57 commit 52d4e8e

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

drivers/lanzou/help.go

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,42 @@ func RemoveNotes(html string) string {
7878
})
7979
}
8080

81+
// 清理JS注释
82+
func RemoveJSComment(data string) string {
83+
var result strings.Builder
84+
inComment := false
85+
inSingleLineComment := false
86+
87+
for i := 0; i < len(data); i++ {
88+
v := data[i]
89+
90+
if inSingleLineComment && (v == '\n' || v == '\r') {
91+
inSingleLineComment = false
92+
result.WriteByte(v)
93+
continue
94+
}
95+
if inComment && v == '*' && i+1 < len(data) && data[i+1] == '/' {
96+
inComment = false
97+
continue
98+
}
99+
if v == '/' && i+1 < len(data) {
100+
nextChar := data[i+1]
101+
if nextChar == '*' {
102+
inComment = true
103+
i++
104+
continue
105+
} else if nextChar == '/' {
106+
inSingleLineComment = true
107+
i++
108+
continue
109+
}
110+
}
111+
result.WriteByte(v)
112+
}
113+
114+
return result.String()
115+
}
116+
81117
var findAcwScV2Reg = regexp.MustCompile(`arg1='([0-9A-Z]+)'`)
82118

83119
// 在页面被过多访问或其他情况下,有时候会先返回一个加密的页面,其执行计算出一个acw_sc__v2后放入页面后再重新访问页面才能获得正常页面

drivers/lanzou/util.go

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -348,6 +348,10 @@ func (d *LanZou) getFilesByShareUrl(shareID, pwd string, sharePageData string) (
348348
file FileOrFolderByShareUrl
349349
)
350350

351+
// 删除注释
352+
sharePageData = RemoveNotes(sharePageData)
353+
sharePageData = RemoveJSComment(sharePageData)
354+
351355
// 需要密码
352356
if strings.Contains(sharePageData, "pwdload") || strings.Contains(sharePageData, "passwddiv") {
353357
sharePageData, err := getJSFunctionByName(sharePageData, "down_p")

0 commit comments

Comments
 (0)