Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: semicolons need escaping in grub.cfg #56

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 7 additions & 2 deletions livefs_edit/actions.py
Original file line number Diff line number Diff line change
Expand Up @@ -335,6 +335,11 @@ def cmdline_config_files(ctxt):

@register_action()
def add_cmdline_arg(ctxt, arg, persist: bool = True):
def escape_arg():
if path.endswith('boot/grub/grub.cfg'):
return arg.replace(';', r'\;')
return arg

for path in cmdline_config_files(ctxt):
with ctxt.logged(f'rewriting {path}'):
with open(path) as fp:
Expand All @@ -343,10 +348,10 @@ def add_cmdline_arg(ctxt, arg, persist: bool = True):
for line in inputlines:
if '---' in line:
if persist:
line = line.rstrip() + ' ' + arg + '\n'
line = line.rstrip() + ' ' + escape_arg() + '\n'
else:
before, after = line.split('---', 1)
line = before.rstrip() + ' ' + arg + ' ---' + after
line = before.rstrip() + ' ' + escape_arg() + ' ---' + after
outfp.write(line)


Expand Down