From f3656fdbd094af96e84199403c7060d7b7fa6e8c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leon=20B=C3=B6sche?= Date: Sat, 10 Jan 2026 03:40:46 +0100 Subject: [PATCH] Normalize folder names to prevent leading/trailing slashes in folder creation --- b0esche_cloud/lib/pages/file_explorer.dart | 11 +++++++---- b0esche_cloud/lib/services/file_service.dart | 14 +++++++++++--- 2 files changed, 18 insertions(+), 7 deletions(-) diff --git a/b0esche_cloud/lib/pages/file_explorer.dart b/b0esche_cloud/lib/pages/file_explorer.dart index 3d1a908..bc4611f 100644 --- a/b0esche_cloud/lib/pages/file_explorer.dart +++ b/b0esche_cloud/lib/pages/file_explorer.dart @@ -130,10 +130,13 @@ class _FileExplorerState extends State { onPressed: () { final folderName = controller.text.trim(); if (folderName.isNotEmpty) { - final nameWithSlash = folderName.startsWith('/') - ? folderName - : '/$folderName'; - Navigator.of(context).pop(nameWithSlash); + // Strip any leading/trailing slashes so we only send the bare folder name + final sanitized = folderName + .replaceAll(RegExp(r'^/+'), '') + .replaceAll(RegExp(r'/+$'), ''); + if (sanitized.isNotEmpty) { + Navigator.of(context).pop(sanitized); + } } }, child: const Text( diff --git a/b0esche_cloud/lib/services/file_service.dart b/b0esche_cloud/lib/services/file_service.dart index 17bd493..362b20c 100644 --- a/b0esche_cloud/lib/services/file_service.dart +++ b/b0esche_cloud/lib/services/file_service.dart @@ -119,20 +119,28 @@ class FileService { String parentPath, String folderName, ) async { + // Normalize folder name to avoid accidental leading slashes creating double-slash paths + final normalizedName = folderName + .replaceAll(RegExp(r'^/+'), '') + .replaceAll(RegExp(r'/+$'), ''); + if (normalizedName.isEmpty) { + throw Exception('Folder name cannot be empty'); + } + // Construct proper path: /parent/folder or /folder for root String path; if (parentPath == '/') { - path = '/$folderName'; + path = '/$normalizedName'; } else { // Ensure parentPath doesn't end with / before appending final cleanParent = parentPath.endsWith('/') ? parentPath.substring(0, parentPath.length - 1) : parentPath; - path = '$cleanParent/$folderName'; + path = '$cleanParent/$normalizedName'; } final data = { - 'name': folderName, + 'name': normalizedName, 'path': path, 'type': 'folder', 'size': 0,