Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions src/openjd/model/v2023_09/_model.py
Original file line number Diff line number Diff line change
Expand Up @@ -509,6 +509,10 @@ def _validate_name(cls, v: str, info: ValidationInfo) -> str:
def _validate_filename(cls, v: Optional[Filename], info: ValidationInfo) -> Optional[Filename]:
if v is None:
return v
if "/" in v or "\\" in v:
raise ValueError(
"filename must be a basename only and cannot contain path separators ('/' or '\\\\')"
)
context = cast(Optional[ModelParsingContext], info.context)
max_len = 256 if context and "FEATURE_BUNDLE_1" in context.extensions else 64
if len(v) > max_len:
Expand Down
9 changes: 8 additions & 1 deletion test/openjd/model/v2023_09/test_embedded.py
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,14 @@ def test_parse_success(self, data: dict[str, Any]) -> None:
{"name": "foo", "type": "TEXT", "data": "some text", "runnable": "True"},
id="runnable must be bool",
),
# TODO - tests for filename allowed characters
pytest.param(
{"name": "foo", "type": "TEXT", "data": "some text", "filename": "dir/file.txt"},
id="filename with forward slash",
),
pytest.param(
{"name": "foo", "type": "TEXT", "data": "some text", "filename": "dir\\file.txt"},
id="filename with backslash",
),
),
)
def test_parse_fails(self, data: dict[str, Any]) -> None:
Expand Down
Loading