Skip to content

Commit c2b51cb

Browse files
authored
[emrun] Don't modify argument values when replaceing _ with - (#22047)
Fixes: #22045
1 parent e691941 commit c2b51cb

File tree

2 files changed

+12
-4
lines changed

2 files changed

+12
-4
lines changed

emrun.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1573,7 +1573,10 @@ def parse_args(args):
15731573
if a == '--':
15741574
break
15751575
if a.startswith('--') and '_' in a:
1576-
args[i] = a.replace('_', '-')
1576+
# Only replace '_' in that argument name, not that its value
1577+
parts = a.split('=')
1578+
parts[0] = parts[0].replace('_', '-')
1579+
args[i] = '='.join(parts)
15771580

15781581
return parser.parse_args(args)
15791582

test/test_browser.py

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5658,19 +5658,24 @@ def test_emrun(self):
56585658
args_base,
56595659
args_base + ['--port', '0'],
56605660
args_base + ['--private_browsing', '--port', '6941'],
5661-
args_base + ['--dump_out_directory', 'other dir/multiple', '--port', '6942']
5661+
args_base + ['--dump_out_directory', 'other dir/multiple', '--port', '6942'],
5662+
args_base + ['--dump_out_directory=foo_bar', '--port', '6942'],
56625663
]:
56635664
args += [self.in_dir('hello_world.html'), '--', '1', '2', '--3', 'escaped space', 'with_underscore']
56645665
print(shared.shlex_join(args))
56655666
proc = self.run_process(args, check=False)
56665667
self.assertEqual(proc.returncode, 100)
5667-
dump_dir = 'other dir/multiple' if '--dump_out_directory' in args else 'dump_out'
5668+
dump_dir = 'dump_out'
5669+
if '--dump_out_directory' in args:
5670+
dump_dir = 'other dir/multiple'
5671+
elif '--dump_out_directory=foo_bar' in args:
5672+
dump_dir = 'foo_bar'
56685673
self.assertExists(self.in_dir(f'{dump_dir}/test.dat'))
56695674
self.assertExists(self.in_dir(f'{dump_dir}/heap.dat'))
56705675
self.assertExists(self.in_dir(f'{dump_dir}/nested/with space.dat'))
56715676
stdout = read_file(self.in_dir('stdout.txt'))
56725677
stderr = read_file(self.in_dir('stderr.txt'))
5673-
self.assertContained('argc: 5', stdout)
5678+
self.assertContained('argc: 6', stdout)
56745679
self.assertContained('argv[3]: --3', stdout)
56755680
self.assertContained('argv[4]: escaped space', stdout)
56765681
self.assertContained('argv[5]: with_underscore', stdout)

0 commit comments

Comments
 (0)