Skip to content

Commit 81a39ea

Browse files
committed
dont allow cross linking
1 parent 6df8b24 commit 81a39ea

File tree

2 files changed

+37
-20
lines changed

2 files changed

+37
-20
lines changed

bapctools/generate.py

Lines changed: 28 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -341,10 +341,18 @@ def default_solution_path(generator_config: "GeneratorConfig") -> Path:
341341
)
342342
UNIQUE_DIRECTORY_KEYS: Final[Sequence[str]] = ("data", "test_group.yaml", "include")
343343
ALLOWED_LINK_KEYS: Final[Sequence[str]] = (
344-
".in.statement",
345-
".ans.statement",
346-
".in.download",
347-
".ans.download",
344+
"in.statement",
345+
"ans.statement",
346+
"in.download",
347+
"ans.download",
348+
)
349+
ALLOWED_LINK_VALUES: Final[Sequence[str]] = (
350+
"in",
351+
"in.statement",
352+
"in.download",
353+
"ans",
354+
"ans.statement",
355+
"ans.download",
348356
)
349357
KNOWN_DIRECTORY_KEYS: Final[Sequence[str]] = (
350358
"type",
@@ -622,27 +630,33 @@ def __init__(
622630

623631
# 3./4. hardcoded data or link to another file
624632
for ext in config.KNOWN_TEXT_DATA_EXTENSIONS:
625-
if ext[1:] in yaml:
626-
value = yaml[ext[1:]]
627-
if ext == ".yaml":
633+
key = ext[1:]
634+
if key in yaml:
635+
value = yaml[key]
636+
if key == "yaml":
628637
# yaml can only be hardcoded (convert dict -> str)
629638
if not isinstance(value, str):
630639
value = write_yaml(value)
631640
assert value is not None
632-
if isinstance(value, dict) and ext in ALLOWED_LINK_KEYS:
641+
if isinstance(value, dict) and key in ALLOWED_LINK_KEYS:
633642
# 4. linked
634643
if "link" not in value or len(value) != 1:
635644
raise ParseException(
636-
f"{ext} should either be a string or a map with only the entry link."
645+
f"{key} should either be a string or a map with only a link entry."
637646
)
638647
value = value["link"]
639-
assert_type(f"{ext}.link", value, str)
640-
value_ext = f".{value}"
641-
if value_ext not in config.KNOWN_TEXT_DATA_EXTENSIONS:
648+
assert_type(f"{key}.link", value, str)
649+
if value not in ALLOWED_LINK_VALUES:
650+
raise ParseException(
651+
f"Unknown value `{value}` for for key {key}.link."
652+
)
653+
key_type = key.split(".", 1)[0]
654+
value_type = value.split(".", 1)[0]
655+
if key_type != value_type:
642656
raise ParseException(
643-
f"Unknown value `{value}` for for key {ext}.link."
657+
f"Crosslinking from {key} to {value} is not allowed."
644658
)
645-
self.linked[ext] = value_ext
659+
self.linked[ext] = f".{value}"
646660
else:
647661
# 3. hardcoded
648662
assert_type(ext, value, str)

bapctools/resources/support/schemas/generators.cue

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,16 @@ import "strings"
8080
ans?: string
8181
out?: string
8282

83-
let literal_or_link = string | {
84-
link: "in" | "in.statement" | "in.download" | "ans" | "ans.statement" | "ans.download" | "out"
83+
let literal_or_in_link = string | {
84+
link: "in" | "in.statement" | "in.download"
8585
}
86-
"in.statement"?: literal_or_link
87-
"in.download"?: literal_or_link
88-
"ans.statement"?: literal_or_link
89-
"ans.download"?: literal_or_link
86+
let literal_or_ans_link = string | {
87+
link: "ans" | "ans.statement" | "ans.download"
88+
}
89+
"in.statement"?: literal_or_in_link
90+
"in.download"?: literal_or_in_link
91+
"ans.statement"?: literal_or_ans_link
92+
"ans.download"?: literal_or_ans_link
9093

9194
interaction?: =~"^([<>][^\\n]*\\n|---\\n)+$"
9295
yaml?: #test_case_configuration

0 commit comments

Comments
 (0)