fill_config: fix multiple command expansions
If there are multiple ${foo()} commands expanded in one iteration, there would
be offset mismatches because the changed string was used with regex offsets
from before the match. Re-run the regex after each change.
Change-Id: I69de60d840ff3ba115c37d1ede7ccbc8879c82eb
diff --git a/net/fill_config.py b/net/fill_config.py
index 665926a..e97dab7 100755
--- a/net/fill_config.py
+++ b/net/fill_config.py
@@ -189,9 +189,12 @@
return ''.join(expanded)
def handle_commands(tmpl, tmpl_dir, tmpl_src, local_config):
- handled = 0
- for m in command_re.finditer(tmpl):
- handled += 1
+ while True:
+ # make sure to re-run the regex after each expansion to get proper string
+ # offsets each time
+ m = command_re.search(tmpl)
+ if not m:
+ break;
cmd = m.group(1)
arg = m.group(2)
if cmd == 'include':
@@ -202,6 +205,9 @@
print('Error: unknown command: %r in %r' % (cmd, tmpl_src))
exit(1)
+ # There was some command expansion. Go again.
+ continue
+
return tmpl
for tmpl_name in sorted(os.listdir(tmpl_dir)):