From 45af48e46df72eb307840bdc1db4ac9a42e5d27f Mon Sep 17 00:00:00 2001 From: Claude Date: Wed, 22 Apr 2026 15:01:53 +0000 Subject: [PATCH] Fix Python config parser swallowing inline comments as part of values read_config / _read_conf now strips trailing inline shell comments (whitespace + # + anything) before processing the value. Without this, a line like: SUNRISE_CAM=east # which camera faces east produced SUNRISE_CAM = 'east # which camera faces east', causing sunrise2mm.py to build a path with the comment embedded in it. The regex \s+#.*$ requires at least one whitespace before # so passwords or URLs containing # (e.g. %23 URL-encoded) are unaffected. https://claude.ai/code/session_01C4jbd3waXG3eKZYbGUjLUQ --- sunrise.py | 4 +++- sunrise2mm.py | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/sunrise.py b/sunrise.py index 9db1156..1db47d1 100755 --- a/sunrise.py +++ b/sunrise.py @@ -18,7 +18,9 @@ def _read_conf(path): continue k, v = line.split('=', 1) k = k.strip() - v = v.strip().strip('"').strip("'") + v = v.strip() + v = re.sub(r'\s+#.*$', '', v) # strip inline comments + v = v.strip('"').strip("'") # Extract default from bash ${VAR:-default} pattern m = re.match(r'^\$\{[^}]+:-([^}]*)\}$', v) if m: diff --git a/sunrise2mm.py b/sunrise2mm.py index e999d56..f51355e 100755 --- a/sunrise2mm.py +++ b/sunrise2mm.py @@ -20,7 +20,9 @@ def read_config(path): continue k, v = line.split('=', 1) k = k.strip() - v = v.strip().strip('"').strip("'") + v = v.strip() + v = re.sub(r'\s+#.*$', '', v) # strip inline comments + v = v.strip('"').strip("'") m = re.match(r'^\$\{[^}]+:-([^}]*)\}$', v) if m: v = m.group(1).strip('"').strip("'")