|
5 | 5 | import base64 |
6 | 6 | from datetime import datetime |
7 | 7 | import json |
8 | | -import os |
9 | 8 | import pytest |
10 | 9 | from flask import url_for, current_app |
11 | 10 | from sqlalchemy import desc |
12 | 11 | import os |
13 | 12 | from unittest.mock import patch |
14 | 13 | from pathvalidate import sanitize_filename |
15 | 14 | from pygeodiff import GeoDiff |
| 15 | +from pathlib import PureWindowsPath |
16 | 16 |
|
17 | 17 | from ..utils import save_diagnostic_log_file |
18 | 18 |
|
|
24 | 24 | is_valid_path, |
25 | 25 | get_x_accel_uri, |
26 | 26 | wkb2wkt, |
| 27 | + has_trailing_space, |
27 | 28 | ) |
28 | 29 | from ..auth.models import LoginHistory, User |
29 | 30 | from . import json_headers |
@@ -228,6 +229,24 @@ def test_is_valid_path(client, filepath, allow): |
228 | 229 | assert is_valid_path(filepath) == allow |
229 | 230 |
|
230 | 231 |
|
| 232 | +trailing_spaces_paths = [ |
| 233 | + ("photos /lutraHQ.jpg", "posix", True), |
| 234 | + ("photo s/ lutraHQ.jpg", "posix", False), |
| 235 | + ("assets\photos \lutraHQ.jpg", "windows", True), |
| 236 | + ("assets\ photos\lutraHQ.jpg", "windows", False), |
| 237 | +] |
| 238 | + |
| 239 | + |
| 240 | +@pytest.mark.parametrize("path,path_platform,result", trailing_spaces_paths) |
| 241 | +def test_has_trailing_space(path, path_platform, result): |
| 242 | + if path_platform == "windows": |
| 243 | + # we must mock Path to instantiate as Windows path |
| 244 | + with patch("mergin.sync.utils.Path", PureWindowsPath): |
| 245 | + assert has_trailing_space(path) is result |
| 246 | + else: |
| 247 | + assert has_trailing_space(path) is result |
| 248 | + |
| 249 | + |
231 | 250 | def test_get_x_accell_uri(client): |
232 | 251 | """Test get_x_accell_uri""" |
233 | 252 | client.application.config["LOCAL_PROJECTS"] = "/data/" |
|
0 commit comments