@@ -28,6 +28,7 @@ import (
2828 "github.com/88250/lute"
2929 "github.com/88250/lute/html"
3030 "github.com/gin-gonic/gin"
31+ "github.com/siyuan-note/filelock"
3132 "github.com/siyuan-note/logging"
3233 "github.com/siyuan-note/siyuan/kernel/conf"
3334 "github.com/siyuan-note/siyuan/kernel/model"
@@ -171,13 +172,12 @@ func getEmojiConf(c *gin.Context) {
171172 }
172173
173174 if ! util .IsValidUploadFileName (html .UnescapeString (name )) {
174- emojiFullName := customConfDir + "/" + name
175- fullPathFilteredName := customConfDir + "/" + util .FilterUploadFileName (name )
175+ emojiFullName := filepath . Join ( customConfDir , name )
176+ fullPathFilteredName := filepath . Join ( customConfDir , util .FilterUploadFileName (name ) )
176177 // XSS through emoji name https://github.com/siyuan-note/siyuan/issues/15034
177- logging .LogWarnf ("invalid custom emoji name [%s]" , name )
178- logging .LogErrorf ("renaming invalid file to [%s] in emojis" , fullPathFilteredName )
179- if removeErr := os .Rename (emojiFullName , fullPathFilteredName ); nil != removeErr {
180- logging .LogErrorf ("renaming invalid file to [%s] failed: %s" , fullPathFilteredName , removeErr )
178+ logging .LogWarnf ("renaming invalid custom emoji file [%s] to [%s]" , name , fullPathFilteredName )
179+ if removeErr := filelock .Rename (emojiFullName , fullPathFilteredName ); nil != removeErr {
180+ logging .LogErrorf ("renaming invalid custom emoji file to [%s] failed: %s" , fullPathFilteredName , removeErr )
181181 }
182182 }
183183
@@ -200,13 +200,12 @@ func getEmojiConf(c *gin.Context) {
200200 }
201201
202202 if ! util .IsValidUploadFileName (html .UnescapeString (name )) {
203- emojiFullName := customConfDir + "/" + name
204- fullPathFilteredName := customConfDir + "/" + util .FilterUploadFileName (name )
203+ emojiFullName := filepath . Join ( customConfDir , name )
204+ fullPathFilteredName := filepath . Join ( customConfDir , util .FilterUploadFileName (name ) )
205205 // XSS through emoji name https://github.com/siyuan-note/siyuan/issues/15034
206- logging .LogWarnf ("invalid custom emoji name [%s]" , name )
207- logging .LogErrorf ("renaming invalid file to [%s] in emojis" , fullPathFilteredName )
208- if removeErr := os .Rename (emojiFullName , fullPathFilteredName ); nil != removeErr {
209- logging .LogErrorf ("renaming invalid file to [%s] failed: %s" , fullPathFilteredName , removeErr )
206+ logging .LogWarnf ("renaming invalid custom emoji file [%s] to [%s]" , name , fullPathFilteredName )
207+ if removeErr := filelock .Rename (emojiFullName , fullPathFilteredName ); nil != removeErr {
208+ logging .LogErrorf ("renaming invalid custom emoji file to [%s] failed: %s" , fullPathFilteredName , removeErr )
210209 }
211210 }
212211
0 commit comments