Skip to content

Commit

Permalink
Add additional check for project.license.file
Browse files Browse the repository at this point in the history
  • Loading branch information
cdce8p committed Feb 20, 2025
1 parent 5f8c75f commit 0f8482a
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
6 changes: 5 additions & 1 deletion flit_core/flit_core/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -608,9 +608,13 @@ def read_pep621_metadata(proj, path) -> LoadedConfig:
raise ConfigError(
f"License file path ({license_f}) cannot be an absolute path"
)
if ".." in license_f:
raise ConfigError(
f"License file path ({license_f}) cannot contain '..'"
)
if not (path.parent / license_f).is_file():
raise ConfigError(f"License file {license_f} does not exist")
license_files.add(license_tbl['file'])
license_files.add(license_f)
elif 'text' in license_tbl:
pass
else:
Expand Down
9 changes: 9 additions & 0 deletions flit_core/tests_core/test_config.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import logging
import re
import sys
from pathlib import Path
import pytest
Expand Down Expand Up @@ -139,6 +140,14 @@ def test_bad_include_paths(path, err_match):
({'version': 1}, r'\bstr\b'),
({'license': {'fromage': 2}}, '[Uu]nrecognised'),
({'license': {'file': 'LICENSE', 'text': 'xyz'}}, 'both'),
(
{'license': {'file': '/LICENSE'}},
re.escape("License file path (/LICENSE) cannot be an absolute path"),
),
(
{'license': {'file': '../LICENSE'}},
re.escape("License file path (../LICENSE) cannot contain '..'"),
),
({'license': {}}, 'required'),
({'license': 1}, "license field should be <class 'str'> or <class 'dict'>, not <class 'int'>"),
# ({'license': "MIT License"}, "Invalid license expression: 'MIT License'"), # TODO
Expand Down

0 comments on commit 0f8482a

Please sign in to comment.