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
This commit is contained in:
+3
-1
@@ -18,7 +18,9 @@ def _read_conf(path):
|
|||||||
continue
|
continue
|
||||||
k, v = line.split('=', 1)
|
k, v = line.split('=', 1)
|
||||||
k = k.strip()
|
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
|
# Extract default from bash ${VAR:-default} pattern
|
||||||
m = re.match(r'^\$\{[^}]+:-([^}]*)\}$', v)
|
m = re.match(r'^\$\{[^}]+:-([^}]*)\}$', v)
|
||||||
if m:
|
if m:
|
||||||
|
|||||||
+3
-1
@@ -20,7 +20,9 @@ def read_config(path):
|
|||||||
continue
|
continue
|
||||||
k, v = line.split('=', 1)
|
k, v = line.split('=', 1)
|
||||||
k = k.strip()
|
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)
|
m = re.match(r'^\$\{[^}]+:-([^}]*)\}$', v)
|
||||||
if m:
|
if m:
|
||||||
v = m.group(1).strip('"').strip("'")
|
v = m.group(1).strip('"').strip("'")
|
||||||
|
|||||||
Reference in New Issue
Block a user