Fix allowed_nodes sanitizer indentation handling
This commit is contained in:
parent
2452674c3c
commit
3223a3a432
1 changed files with 21 additions and 21 deletions
|
|
@ -112,55 +112,55 @@ update_allowed_nodes() {
|
||||||
|
|
||||||
# Remove any existing allowed_nodes block (including descriptive comments) to prevent duplicates
|
# Remove any existing allowed_nodes block (including descriptive comments) to prevent duplicates
|
||||||
if command -v python3 >/dev/null 2>&1; then
|
if command -v python3 >/dev/null 2>&1; then
|
||||||
python3 - "$config_file" <<'PY' || true
|
python3 - "$config_file" <<'PY'
|
||||||
import sys
|
import sys
|
||||||
from pathlib import Path
|
from pathlib import Path
|
||||||
|
|
||||||
path = Path(sys.argv[1])
|
path = Path(sys.argv[1])
|
||||||
text = path.read_text().splitlines()
|
lines = path.read_text().splitlines()
|
||||||
|
if not lines:
|
||||||
|
path.write_text('')
|
||||||
|
exit()
|
||||||
|
|
||||||
out = []
|
out = []
|
||||||
pending = []
|
pending = []
|
||||||
skip = False
|
skip = False
|
||||||
|
|
||||||
def flush_pending(buf, output):
|
def flush_pending():
|
||||||
if buf:
|
global pending
|
||||||
output.extend(buf)
|
if pending:
|
||||||
buf.clear()
|
out.extend(pending)
|
||||||
|
pending = []
|
||||||
|
|
||||||
i = 0
|
i = 0
|
||||||
while i < len(text):
|
while i < len(lines):
|
||||||
line = text[i]
|
line = lines[i]
|
||||||
stripped = line.lstrip()
|
stripped = line.lstrip()
|
||||||
|
|
||||||
if skip:
|
if skip:
|
||||||
if stripped == "" or stripped.startswith("#") or stripped.startswith("-"):
|
indent = len(line) - len(stripped)
|
||||||
|
if indent > 0 or stripped.startswith('#'):
|
||||||
i += 1
|
i += 1
|
||||||
continue
|
continue
|
||||||
if line.startswith(" "):
|
|
||||||
# still part of allowed_nodes indentation (e.g., comments), skip
|
|
||||||
if stripped.startswith("allowed_nodes:"):
|
|
||||||
# unexpected nested block; continue handling
|
|
||||||
i += 1
|
|
||||||
continue
|
|
||||||
skip = False
|
skip = False
|
||||||
|
|
||||||
if stripped.startswith("allowed_nodes:"):
|
if stripped.startswith('allowed_nodes:'):
|
||||||
pending.clear()
|
pending = []
|
||||||
skip = True
|
skip = True
|
||||||
i += 1
|
i += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
if stripped == "" or stripped.startswith("#"):
|
if stripped == '' or stripped.startswith('#'):
|
||||||
pending.append(line)
|
pending.append(line)
|
||||||
i += 1
|
i += 1
|
||||||
continue
|
continue
|
||||||
|
|
||||||
flush_pending(pending, out)
|
flush_pending()
|
||||||
out.append(line)
|
out.append(line)
|
||||||
i += 1
|
i += 1
|
||||||
|
|
||||||
flush_pending(pending, out)
|
flush_pending()
|
||||||
path.write_text("\n".join(out) + ("\n" if text else ""))
|
path.write_text('\n'.join(out) + '\n')
|
||||||
PY
|
PY
|
||||||
else
|
else
|
||||||
# Fallback: truncate the file to remove duplicates if python3 is unavailable
|
# Fallback: truncate the file to remove duplicates if python3 is unavailable
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue