From d0a8df768ea385abb63db5da6806f0604d055668 Mon Sep 17 00:00:00 2001 From: MadDogOwner Date: Wed, 16 Apr 2025 05:27:54 +0800 Subject: [PATCH 1/3] feat(lanzou): add RemoveJSComment function to clean JavaScript comments from HTML --- drivers/lanzou/help.go | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) diff --git a/drivers/lanzou/help.go b/drivers/lanzou/help.go index 81d7c567d5c..458aab85ed1 100644 --- a/drivers/lanzou/help.go +++ b/drivers/lanzou/help.go @@ -78,6 +78,45 @@ 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 { + if v == '*' && i+1 < len(data) && data[i+1] == '/' { + inComment = false + i++ + } + 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后放入页面后再重新访问页面才能获得正常页面 From c088f645679381fdbd85dbb3c9ecb10a0341be4a Mon Sep 17 00:00:00 2001 From: MadDogOwner Date: Wed, 16 Apr 2025 05:28:24 +0800 Subject: [PATCH 2/3] feat(lanzou): remove comments from share page data in getFilesByShareUrl function --- drivers/lanzou/util.go | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/drivers/lanzou/util.go b/drivers/lanzou/util.go index 4b9959ad53d..e66252bcc79 100644 --- a/drivers/lanzou/util.go +++ b/drivers/lanzou/util.go @@ -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") From 8b6fb5ed111d0f38d8d140ca9c81cccbe15660e1 Mon Sep 17 00:00:00 2001 From: MadDogOwner Date: Wed, 16 Apr 2025 06:01:00 +0800 Subject: [PATCH 3/3] fix(lanzou): optimize RemoveJSComment function to improve comment removal logic --- drivers/lanzou/help.go | 7 ++----- 1 file changed, 2 insertions(+), 5 deletions(-) diff --git a/drivers/lanzou/help.go b/drivers/lanzou/help.go index 458aab85ed1..c3f5c6bb5bc 100644 --- a/drivers/lanzou/help.go +++ b/drivers/lanzou/help.go @@ -92,11 +92,8 @@ func RemoveJSComment(data string) string { result.WriteByte(v) continue } - if inComment { - if v == '*' && i+1 < len(data) && data[i+1] == '/' { - inComment = false - i++ - } + if inComment && v == '*' && i+1 < len(data) && data[i+1] == '/' { + inComment = false continue } if v == '/' && i+1 < len(data) {