Skip to content

Commit fe5be6a

Browse files
authored
Fix config string parsing for windows pathnames (with backslashes) (emscripten-core#27408)
By using `shlex.shlex(x, posix=True)` and clearing `lexer.escape`, config strings are parsed with POSIX quote handling while allowing Windows paths to be specified with backslashes. See: emscripten-core#27219
1 parent 41ec5c7 commit fe5be6a

4 files changed

Lines changed: 11 additions & 4 deletions

File tree

.circleci/config.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ commands:
158158
echo "import os" >> .emscripten
159159
# We use an out-of-tree cache directory so it can be part of the
160160
# persisted workspace (see below).
161-
echo "CACHE = os.path.expanduser('~/cache')" >> .emscripten
161+
echo "CACHE = '~/cache'" >> .emscripten
162162
# Refer to commit 0bc3640 if we need to pin V8 version.
163163
echo "V8_ENGINE = '~/.jsvu/bin/v8'" >> .emscripten
164164
echo "JS_ENGINES = [NODE_JS]" >> .emscripten

test/test_other.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13271,6 +13271,7 @@ def test_pthread_js_exception(self):
1327113271
self.set_setting('EXIT_RUNTIME')
1327213272
self.do_runf('other/test_pthread_js_exception.c', 'missing is not defined', assert_returncode=NON_ZERO, cflags=['-pthread'])
1327313273

13274+
@crossplatform
1327413275
def test_config_closure_compiler(self):
1327513276
self.run_process([EMCC, test_file('hello_world.c'), '--closure=1'])
1327613277
with env_modify({'EM_CLOSURE_COMPILER': sys.executable}):

test/test_sanity.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -584,7 +584,7 @@ def test_config_listify(self):
584584
cfg_file = os.path.join(config_dir, 'custom_config')
585585

586586
extra_config = '''
587-
NODE_JS = '/path/to/node --with-arg --option="hello world"'
587+
NODE_JS = '"/path/to/node with spaces" --with-arg --option="hello world"'
588588
CLOSURE_COMPILER = ['/path/to/closure', '--legacy-flag']
589589
'''
590590
create_file(cfg_file, get_basic_config() + extra_config, absolute=True)
@@ -594,7 +594,7 @@ def get_em_config(var_name):
594594
return self.run_process([EMCONFIG, var_name], stdout=PIPE, stderr=PIPE)
595595

596596
proc = get_em_config('NODE_JS')
597-
self.assertEqual(proc.stdout.strip(), "['/path/to/node', '--with-arg', '--option=hello world']")
597+
self.assertEqual(proc.stdout.strip(), "['/path/to/node with spaces', '--with-arg', '--option=hello world']")
598598

599599
proc = get_em_config('CLOSURE_COMPILER')
600600
self.assertEqual(proc.stdout.strip(), "['/path/to/closure', '--legacy-flag']")

tools/config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,13 @@ def listify(x):
4040
if type(x) is list:
4141
logger.warning(f'Found list-style config entry ({x}). Please use a single string with spaces between args.')
4242
return x
43-
return shlex.split(x)
43+
# Use posix=True here so that quotes are handled as expected, but clear the
44+
# `escape` list so that backslashes are not treated as escape chars (which
45+
# would break windows pathnames that use backslashes).
46+
lexer = shlex.shlex(x, posix=True)
47+
lexer.escape = []
48+
lexer.whitespace_split = True
49+
return list(lexer)
4450

4551

4652
def normalize_config_settings():

0 commit comments

Comments
 (0)