فهرست منبع

Quick fix for Chinese or Japanese name decode issue on low mem upload mode

Toby Chui 3 سال پیش
والد
کامیت
a49c8fc7b5
2فایلهای تغییر یافته به همراه21 افزوده شده و 2 حذف شده
  1. 14 2
      src/file_system.go
  2. 7 0
      src/web/SystemAO/file_system/file_explorer.html

+ 14 - 2
src/file_system.go

@@ -529,9 +529,17 @@ func system_fs_handleLowMemoryUpload(w http.ResponseWriter, r *http.Request) {
 		//log.Println("recv:", len(message), "type", mt)
 	}
 
-	//Merge the file
+	//Try to decode the location if possible
+	decodedUploadLocation, err := url.QueryUnescape(targetUploadLocation)
+	if err != nil {
+		decodedUploadLocation = targetUploadLocation
+	}
+
+	//Do not allow % sign in filename. Replace all with underscore
+	decodedUploadLocation = strings.ReplaceAll(decodedUploadLocation, "%", "_")
 
-	out, err := os.OpenFile(targetUploadLocation, os.O_CREATE|os.O_WRONLY, 0755)
+	//Merge the file
+	out, err := os.OpenFile(decodedUploadLocation, os.O_CREATE|os.O_WRONLY, 0755)
 	if err != nil {
 		log.Println("Failed to open file:", err)
 		c.WriteMessage(1, []byte(`{\"error\":\"Failed to open destination file\"}`))
@@ -693,6 +701,9 @@ func system_fs_handleUpload(w http.ResponseWriter, r *http.Request) {
 		return
 	}
 
+	//Do not allow % sign in filename. Replace all with underscore
+	destFilepath = strings.ReplaceAll(destFilepath, "%", "_")
+
 	//Prepare the file to be created (uploaded)
 	destination, err := os.Create(destFilepath)
 	if err != nil {
@@ -1155,6 +1166,7 @@ func system_fs_handleNewObjects(w http.ResponseWriter, r *http.Request) {
 			sendErrorResponse(w, "Access Denied")
 			return
 		}
+
 		//Check if the file already exists. If yes, fix its filename.
 		newfilePath := filepath.ToSlash(filepath.Join(rpath, filename))
 

+ 7 - 0
src/web/SystemAO/file_system/file_explorer.html

@@ -3295,6 +3295,13 @@
                         $("#createNewFolder").parent().addClass("error");
                         return;
                     }
+
+                    //Check for invalid characters
+                    if (newFoldername.includes("%")){
+                        $("#createNewFolder").parent().addClass("error");
+                        return;
+                    }
+
                     if (currentFilelist.includes(newFoldername)){
                         //Current filelist already contain a folder with the same name
                         $("#createNewFolder").parent().addClass("error");