Skip to content

Commit

Permalink
explicitly warn against whitespace in app name and filename (#85)
Browse files Browse the repository at this point in the history
  • Loading branch information
dennisvang authored Oct 23, 2023
1 parent 08ff73e commit 82429c8
Show file tree
Hide file tree
Showing 4 changed files with 22 additions and 4 deletions.
4 changes: 3 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,9 @@ Archive filenames and patch filenames follow the pattern

`<name>-<version><suffix>`

where `name` is a short string that may contain alphanumeric characters, underscores, and hyphens, `version` is a version string according to the [PEP440][6] specification, and `suffix` is either `'.tar.gz'` or `'.patch'`.
where `name` is a short string that may *only* contain *alphanumeric characters*, *underscores*, and *hyphens*, `version` is a version string according to the [PEP440][6] specification, and `suffix` is either `'.tar.gz'` or `'.patch'`.

***BEWARE***: *whitespace* is NOT allowed in the filename.

Patches are typically smaller than archives, so the tufup *client* will always attempt to update using one or more patches.
However, if the total amount of patch data is greater than the desired full archive file, a full update will be performed.
Expand Down
2 changes: 1 addition & 1 deletion examples/client/example_app.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
# python -m http.server -d examples/repo/content

# App info
APP_NAME = 'example_app'
APP_NAME = 'example_app' # BEWARE: app name cannot contain whitespace
CURRENT_VERSION = '1.0'

# For this example, all files are stored in the tufup/examples/client
Expand Down
10 changes: 8 additions & 2 deletions src/tufup/common.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,10 @@ def __init__(
is_archive: Optional[bool] = True,
):
"""
Initialize either with target_path, or with name, version, archive.
BEWARE: whitespace is not allowed in the filename,
nor in the `name` or `version` arguments
"""
super().__init__()
if target_path is None:
Expand All @@ -36,6 +38,10 @@ def __init__(
)
self.target_path_str = str(target_path) # keep the original for reference
self.path = pathlib.Path(target_path)
if ' ' in self.filename:
logger.critical(
f'invalid filename "{self.filename}": whitespace not allowed'
)

def __str__(self):
return str(self.target_path_str)
Expand Down Expand Up @@ -85,7 +91,7 @@ def version(self) -> Optional[Version]:
version = Version(match_dict.get('version', ''))
except InvalidVersion:
version = None
logger.debug(f'No valid version in filename: {self.filename}')
logger.critical(f'No valid version in filename: {self.filename}')
return version

@property
Expand Down
10 changes: 10 additions & 0 deletions tests/test_common.py
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import logging
import pathlib

import bsdiff4
Expand All @@ -8,6 +9,15 @@


class TestTargetMeta(TempDirTestCase):
def test_init_whitespace(self):
for kwargs in [
dict(target_path='w h i t e s p a c e-1.2.3.tar.gz'),
dict(name='w h i t e s p a c e'),
]:
with self.subTest(msg=kwargs):
with self.assertLogs(level=logging.CRITICAL):
TargetMeta(**kwargs)

def test_eq_ne(self):
target_meta = TargetMeta()
self.assertEqual(target_meta, TargetMeta())
Expand Down

0 comments on commit 82429c8

Please sign in to comment.