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
17 changes: 16 additions & 1 deletion configurator/box64rc.py
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,18 @@ def section_key_from_header(header: str, arch: Optional[str] = None) -> SectionK
return SectionKey("exact", name.lower(), arch_value)


def normalize_section_input(value: str) -> str:
name = value.strip()
if name.startswith("[") or name.endswith("]"):
if not (name.startswith("[") and name.endswith("]")):
raise ValueError("Invalid section name")
name = name[1:-1].strip()

if not name or any(char in name for char in "\r\n[]#"):
raise ValueError("Invalid section name")
return name


def header_from_key(key: SectionKey) -> str:
if key.kind == "shared":
return "*"
Expand Down Expand Up @@ -168,7 +180,10 @@ def delete_section(self, key: SectionKey) -> None:
section = self.section_for_key(key)
if section is None:
return
del self.lines[section.start : section.end]
delete_end = section.end
if section.assignments:
delete_end = section.assignments[-1].line_index + 1
del self.lines[section.start : delete_end]
self._parse()

def set_assignment(self, section_key: SectionKey, key: str, value: str) -> SectionKey:
Expand Down
Loading
Loading