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):
483
     
483
     
484
     def resolve_path(self, path):
484
     def resolve_path(self, path):
485
         """Resolve a path that may contain ~ or be relative"""
485
         """Resolve a path that may contain ~ or be relative"""
486
+        if path.endswith('/') and path != '/':
487
+            path = path.rstrip('/')
488
+
486
         if path == "~":
489
         if path == "~":
487
             return self.home_directory
490
             return self.home_directory
488
         elif path.startswith("~/"):
491
         elif path.startswith("~/"):
@@ -501,6 +504,9 @@ class FileSystemTree(models.Model):
501
     
504
     
502
     def normalize_path(self, path):
505
     def normalize_path(self, path):
503
         """Normalize a path by resolving .. and . components"""
506
         """Normalize a path by resolving .. and . components"""
507
+        if path.endswith('/') and path != '/':
508
+            path = path.rstrip('/')
509
+            
504
         parts = path.split('/')
510
         parts = path.split('/')
505
         resolved = []
511
         resolved = []
506
         
512
         
backend/apps/trees/views.pymodified
@@ -363,7 +363,12 @@ class FileSystemTreeViewSet(viewsets.ModelViewSet):
363
                 response_data['output'] = message if not success else ""
363
                 response_data['output'] = message if not success else ""
364
                 response_data['current_path'] = tree.player_location
364
                 response_data['current_path'] = tree.player_location
365
             else:
365
             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
+                
367
                 success, message = tree.move_player(target)
372
                 success, message = tree.move_player(target)
368
                 response_data['success'] = success
373
                 response_data['success'] = success
369
                 response_data['output'] = message
374
                 response_data['output'] = message
@@ -383,7 +388,11 @@ class FileSystemTreeViewSet(viewsets.ModelViewSet):
383
                 else:
388
                 else:
384
                     response_data['output'] = "pushd: no other directory"
389
                     response_data['output'] = "pushd: no other directory"
385
             else:
390
             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
+                
387
                 success, message = tree.push_directory(target)
396
                 success, message = tree.push_directory(target)
388
                 response_data['success'] = success
397
                 response_data['success'] = success
389
                 response_data['output'] = message
398
                 response_data['output'] = message