Skip to content

Commit

Permalink
confighelper: fix inline comment parsing
Browse files Browse the repository at this point in the history
Require that inline comments be separated from configuration
data by whitespace.  Unescape comment specifiers that follow
the correct escape sequence.

Signed-off-by:  Eric Callahan <[email protected]>
  • Loading branch information
Arksine committed Oct 6, 2023
1 parent 52ee49e commit 4329241
Showing 1 changed file with 6 additions and 7 deletions.
13 changes: 6 additions & 7 deletions moonraker/confighelper.py
Original file line number Diff line number Diff line change
Expand Up @@ -952,13 +952,12 @@ def _parse_file(
# ignore lines that contain only whitespace/comments
continue
line = line.expandtabs(tabsize=4)
# Remove inline comments
for prefix in "#;":
icmt = line.find(prefix)
if icmt > 0 and line[icmt-1] != "\\":
# inline comment, remove it
line = line[:icmt]
break
# Search for and remove inline comments
cmt_match = re.search(r" +[#;]", line)
if cmt_match is not None:
line = line[:cmt_match.start()]
# Unescape prefix chars that are preceded by whitespace
line = re.sub(r" \\(#|;)", r" \1", line)
line_indent = len(line) - len(line.lstrip())
if opt_indent != -1 and line_indent > opt_indent:
# Multi-line value, append to buffer and resume parsing
Expand Down

0 comments on commit 4329241

Please sign in to comment.