Skip to content

Commit 978a19d

Browse files
crowecawcawepmog
authored andcommitted
fix: reject path separators in embedded filenames
Signed-off-by: Stephen Crowe <6042774+crowecawcaw@users.noreply.github.com>
1 parent 96651fa commit 978a19d

File tree

2 files changed

+12
-1
lines changed

2 files changed

+12
-1
lines changed

src/openjd/model/v2023_09/_model.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -509,6 +509,10 @@ def _validate_name(cls, v: str, info: ValidationInfo) -> str:
509509
def _validate_filename(cls, v: Optional[Filename], info: ValidationInfo) -> Optional[Filename]:
510510
if v is None:
511511
return v
512+
if "/" in v or "\\" in v:
513+
raise ValueError(
514+
"filename must be a basename only and cannot contain path separators ('/' or '\\\\')"
515+
)
512516
context = cast(Optional[ModelParsingContext], info.context)
513517
max_len = 256 if context and "FEATURE_BUNDLE_1" in context.extensions else 64
514518
if len(v) > max_len:

test/openjd/model/v2023_09/test_embedded.py

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,14 @@ def test_parse_success(self, data: dict[str, Any]) -> None:
6363
{"name": "foo", "type": "TEXT", "data": "some text", "runnable": "True"},
6464
id="runnable must be bool",
6565
),
66-
# TODO - tests for filename allowed characters
66+
pytest.param(
67+
{"name": "foo", "type": "TEXT", "data": "some text", "filename": "dir/file.txt"},
68+
id="filename with forward slash",
69+
),
70+
pytest.param(
71+
{"name": "foo", "type": "TEXT", "data": "some text", "filename": "dir\\file.txt"},
72+
id="filename with backslash",
73+
),
6774
),
6875
)
6976
def test_parse_fails(self, data: dict[str, Any]) -> None:

0 commit comments

Comments
 (0)