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