Complete worked example
python
from pathlib import PurePosixPath
def report_name(value):
if not isinstance(value, str) or not value or value != value.strip() or "\\" in value:
raise ValueError("portable relative name required")
path = PurePosixPath(value)
if path.is_absolute() or ".." in path.parts or not path.parts or path.suffix != ".json":
raise ValueError("relative JSON report required")
return path.as_posix()- Reasoning
- Validate a portable relative report name without confusing lexical validation with a filesystem security boundary. Compare the stated values and failure boundary before changing the implementation.