Skip to content

Commit

Permalink
Improving regex for adding future validation, and moving the validato…
Browse files Browse the repository at this point in the history
…r to the correct location block
  • Loading branch information
SeqLaz committed Oct 4, 2024
1 parent df9b740 commit 3ab98ca
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 12 deletions.
22 changes: 11 additions & 11 deletions qfieldsync/core/cloud_converter.py
Original file line number Diff line number Diff line change
Expand Up @@ -128,18 +128,18 @@ def convert(self) -> None: # noqa: C901
)
self.project.removeMapLayer(layer)
continue
else:
# Validate filenames and paths before copying
if not is_valid_filepath(str(layer.filename)):
self.warning.emit(
self.tr("Cloud Converter"),
self.tr(
"The layer '{}' has an invalid filename or path and was therefore removed from the cloud project."
).format(layer.name()),
)
self.project.removeMapLayer(layer)
continue

# Validate filenames and paths before copying
if not is_valid_filepath(layer_source.filename):
self.warning.emit(
self.tr("Cloud Converter"),
self.tr(
"The layer '{}' has an invalid filename or path and was therefore removed from the cloud project."
).format(layer.name()),
)
self.project.removeMapLayer(layer)
continue
else:
layer_source.copy(self.export_dirname, list())
layer.setCustomProperty(
"QFieldSync/cloud_action", layer_source.default_cloud_action
Expand Down
5 changes: 4 additions & 1 deletion qfieldsync/utils/file_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,10 @@ def is_valid_filename(filename: str) -> bool:
Check if the filename is valid.
"""
pattern = re.compile(
r'\A(?!(?:COM[0-9]|CON|LPT[0-9]|NUL|PRN|AUX|com[0-9]|con|lpt[0-9]|nul|prn|aux)|\s|[\.]{2,})[^\\\/:*"?<>|]{1,254}(?<![\s\.])\z'
r'^(?!.*[<>:"/\\|?*])'
r"(?!(?:COM[0-9]|CON|LPT[0-9]|NUL|PRN|AUX|com[0-9]|con|lpt[0-9]|nul|prn|aux)$)"
r'[^\\\/:*"?<>|]{1,254}'
r"(?<![\s\.])$"
)
return bool(pattern.match(filename))

Expand Down

0 comments on commit 3ab98ca

Please sign in to comment.