You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@answer.apache.org by ku...@apache.org on 2024/07/22 06:40:53 UTC

(incubator-answer-plugins) branch main updated: fix(cdn): fix path replace

This is an automated email from the ASF dual-hosted git repository.

kumfo pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/incubator-answer-plugins.git


The following commit(s) were added to refs/heads/main by this push:
     new 7908440  fix(cdn): fix path replace
7908440 is described below

commit 790844039900a2737487576a5c4f39ce7023c0ff
Author: kumfo <ku...@sifou.com>
AuthorDate: Mon Jul 22 14:39:59 2024 +0800

    fix(cdn): fix path replace
---
 cdn-aliyun/aliyun.go | 3 +++
 cdn-s3/s3.go         | 3 +++
 2 files changed, 6 insertions(+)

diff --git a/cdn-aliyun/aliyun.go b/cdn-aliyun/aliyun.go
index 661de9d..b3a22f1 100644
--- a/cdn-aliyun/aliyun.go
+++ b/cdn-aliyun/aliyun.go
@@ -305,6 +305,9 @@ func (c *CDN) rebuildReader(file io.Reader, replaceMap map[string]string) io.Rea
 		if oldStr != "" {
 			if newStr == "" {
 				prefix := c.Config.VisitUrlPrefix + c.Config.ObjectKeyPrefix
+				if prefix[len(prefix)-1:] == "/" {
+					prefix = strings.TrimSuffix(prefix, "/")
+				}
 				newStr = "\"" + prefix + "/static"
 			}
 			res = strings.ReplaceAll(res, oldStr, newStr)
diff --git a/cdn-s3/s3.go b/cdn-s3/s3.go
index 6835dde..2d84195 100644
--- a/cdn-s3/s3.go
+++ b/cdn-s3/s3.go
@@ -296,6 +296,9 @@ func (c *CDN) rebuildReader(file io.Reader, replaceMap map[string]string) io.Rea
 			if oldStr != "" {
 				if newStr == "" {
 					prefix := c.Config.VisitUrlPrefix + c.Config.ObjectKeyPrefix
+					if prefix[len(prefix)-1:] == "/" {
+						prefix = strings.TrimSuffix(prefix, "/")
+					}
 					newStr = "\"" + prefix + "/static"
 				}
 				res = strings.ReplaceAll(res, oldStr, newStr)