Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adding validator for files on converter to cloud project #614

Open
wants to merge 6 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions qfieldsync/core/cloud_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@
"""

from pathlib import Path
import re

from libqfieldsync.layer import LayerSource
from libqfieldsync.utils.file_utils import copy_attachments
Expand Down Expand Up @@ -51,6 +52,15 @@ def __init__(

self.export_dirname = Path(export_dirname)

# Define forbidden characters for Windows filenames
self.forbidden_chars_pattern = re.compile(r'[<>:"/\\|?*]')

def is_valid_filename(self, filename: str) -> bool:
"""
Check if the filename contains any forbidden characters.
"""
return not self.forbidden_chars_pattern.search(filename)

def convert(self) -> None: # noqa: C901
"""
Convert the project to a cloud project.
Expand Down Expand Up @@ -128,6 +138,17 @@ def convert(self) -> None: # noqa: C901
self.project.removeMapLayer(layer)
continue
else:
# Validate filenames before copying
if not self.is_valid_filename(layer.name()):
self.warning.emit(
self.tr("Cloud Converter"),
self.tr(
"The layer '{}' has an invalid filename and was therefore removed from the cloud project."
).format(layer.name()),
)
self.project.removeMapLayer(layer)
continue

layer_source.copy(self.export_dirname, list())
layer.setCustomProperty(
"QFieldSync/cloud_action", layer_source.default_cloud_action
Expand Down
Loading