diff options
author | Neels Hofmeyr <neels@hofmeyr.de> | 2018-11-26 01:18:08 +0100 |
---|---|---|
committer | Neels Hofmeyr <neels@hofmeyr.de> | 2018-11-26 01:20:03 +0100 |
commit | e7cb4a591c6f54432c25cf32d339b7510587c906 (patch) | |
tree | 2997f90914e238292bac4990986e8e2e88d3aef3 | |
parent | 3c093457d24c2e2ef80a9b53c944fd47cc636851 (diff) |
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
-rwxr-xr-x | net/fill_config.py | 12 |
1 files changed, 9 insertions, 3 deletions
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 @@ def insert_foreach(tmpl, tmpl_dir, tmpl_src, match, local_config, arg): 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 @@ def handle_commands(tmpl, tmpl_dir, tmpl_src, local_config): 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)): |