Skip to content

Commit 8d5ec8c

Browse files
authored
Merge pull request #725 from cdce8p/license-file-check
Add additional check for project.license.file
2 parents ad93dbb + 6cb7ad4 commit 8d5ec8c

File tree

2 files changed

+21
-6
lines changed

2 files changed

+21
-6
lines changed

flit_core/flit_core/config.py

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -473,7 +473,7 @@ def _license_files_from_globs(project_dir: Path, globs, warn_no_files = True):
473473
)
474474
try:
475475
files = [
476-
str(file.relative_to(project_dir)).replace(osp.sep, "/")
476+
file.relative_to(project_dir).as_posix()
477477
for file in project_dir.glob(pattern)
478478
if file.is_file()
479479
]
@@ -603,14 +603,20 @@ def read_pep621_metadata(proj, path) -> LoadedConfig:
603603
raise ConfigError(
604604
"[project.license] should specify file or text, not both"
605605
)
606-
license_f = license_tbl['file']
606+
license_f = osp.normpath(license_tbl['file'])
607607
if isabs_ish(license_f):
608608
raise ConfigError(
609-
f"License file path ({license_f}) cannot be an absolute path"
609+
f"License file path ({license_tbl['file']}) cannot be an absolute path"
610610
)
611-
if not (path.parent / license_f).is_file():
612-
raise ConfigError(f"License file {license_f} does not exist")
613-
license_files.add(license_tbl['file'])
611+
if license_f.startswith('..' + os.sep):
612+
raise ConfigError(
613+
f"License file path ({license_tbl['file']}) cannot contain '..'"
614+
)
615+
license_p = path.parent / license_f
616+
if not license_p.is_file():
617+
raise ConfigError(f"License file {license_tbl['file']} does not exist")
618+
license_f = license_p.relative_to(path.parent).as_posix()
619+
license_files.add(license_f)
614620
elif 'text' in license_tbl:
615621
pass
616622
else:

flit_core/tests_core/test_config.py

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import logging
2+
import re
23
import sys
34
from pathlib import Path
45
import pytest
@@ -139,6 +140,14 @@ def test_bad_include_paths(path, err_match):
139140
({'version': 1}, r'\bstr\b'),
140141
({'license': {'fromage': 2}}, '[Uu]nrecognised'),
141142
({'license': {'file': 'LICENSE', 'text': 'xyz'}}, 'both'),
143+
(
144+
{'license': {'file': '/LICENSE'}},
145+
re.escape("License file path (/LICENSE) cannot be an absolute path"),
146+
),
147+
(
148+
{'license': {'file': '../LICENSE'}},
149+
re.escape("License file path (../LICENSE) cannot contain '..'"),
150+
),
142151
({'license': {}}, 'required'),
143152
({'license': 1}, "license field should be <class 'str'> or <class 'dict'>, not <class 'int'>"),
144153
# ({'license': "MIT License"}, "Invalid license expression: 'MIT License'"), # TODO

0 commit comments

Comments
 (0)