zeroed-some/bashamole / 3bc2376

Browse files

allow trailing slashes

Authored by mfwolffe <wolffemf@dukes.jmu.edu>
SHA
3bc237667b4996c458bcb85b68c5d8f471372594
Parents
74329cd
Tree
ec942a9

2 changed files

StatusFile+-
M backend/apps/trees/models.py 6 0
M backend/apps/trees/views.py 11 2
backend/apps/trees/models.pymodified
@@ -483,6 +483,9 @@ class FileSystemTree(models.Model):
483483
     
484484
     def resolve_path(self, path):
485485
         """Resolve a path that may contain ~ or be relative"""
486
+        if path.endswith('/') and path != '/':
487
+            path = path.rstrip('/')
488
+
486489
         if path == "~":
487490
             return self.home_directory
488491
         elif path.startswith("~/"):
@@ -501,6 +504,9 @@ class FileSystemTree(models.Model):
501504
     
502505
     def normalize_path(self, path):
503506
         """Normalize a path by resolving .. and . components"""
507
+        if path.endswith('/') and path != '/':
508
+            path = path.rstrip('/')
509
+            
504510
         parts = path.split('/')
505511
         resolved = []
506512
         
backend/apps/trees/views.pymodified
@@ -363,7 +363,12 @@ class FileSystemTreeViewSet(viewsets.ModelViewSet):
363363
                 response_data['output'] = message if not success else ""
364364
                 response_data['current_path'] = tree.player_location
365365
             else:
366
-                target = parts[1]
366
+                # Join all parts after 'cd' to handle paths with spaces
367
+                target = ' '.join(parts[1:])
368
+                # Strip trailing slash if present (except for root)
369
+                if target.endswith('/') and target != '/':
370
+                    target = target.rstrip('/')
371
+                
367372
                 success, message = tree.move_player(target)
368373
                 response_data['success'] = success
369374
                 response_data['output'] = message
@@ -383,7 +388,11 @@ class FileSystemTreeViewSet(viewsets.ModelViewSet):
383388
                 else:
384389
                     response_data['output'] = "pushd: no other directory"
385390
             else:
386
-                target = parts[1]
391
+                target = ' '.join(parts[1:])
392
+                # Strip trailing slash if present (except for root)
393
+                if target.endswith('/') and target != '/':
394
+                    target = target.rstrip('/')
395
+                
387396
                 success, message = tree.push_directory(target)
388397
                 response_data['success'] = success
389398
                 response_data['output'] = message