Skip to content

Commit 75f5315

Browse files
authored
Fix unicode characters in js library (#16981)
* Update unicode JS library test to cover more unicode characters that are typically used in the localized names of different languages. * Fix expanded test_unicode_js_library to work.
1 parent 5ba3744 commit 75f5315

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

emscripten.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -181,7 +181,7 @@ def compile_settings():
181181
env['EMCC_BUILD_DIR'] = os.getcwd()
182182
out = shared.run_js_tool(path_from_root('src/compiler.js'),
183183
[settings_file], stdout=subprocess.PIPE, stderr=stderr_file,
184-
cwd=path_from_root('src'), env=env)
184+
cwd=path_from_root('src'), env=env, encoding='utf-8')
185185
assert '//FORWARDED_DATA:' in out, 'Did not receive forwarded data in pre output - process failed?'
186186
glue, forwarded_data = out.split('//FORWARDED_DATA:')
187187
return glue, forwarded_data
@@ -387,7 +387,7 @@ def emscript(in_wasm, out_wasm, outfile_js, memfile):
387387
('// === Body ===\n\n' + asm_const_map +
388388
'\n'.join(em_js_funcs) + '\n'))
389389

390-
with open(outfile_js, 'w') as out:
390+
with open(outfile_js, 'w', encoding='utf-8') as out:
391391
out.write(normalize_line_endings(pre))
392392
pre = None
393393

tests/test_core.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6209,7 +6209,7 @@ def test_unicode_js_library(self):
62096209
}
62106210
''')
62116211
self.emcc_args += ['--js-library', test_file('unicode_library.js')]
6212-
self.do_runf('main.cpp', u'Unicode snowman \u2603 says hello!')
6212+
self.do_runf('main.cpp', u'Unicode snowman \u2603 says hello! \u00e0\u010c\u0161\u00f1\u00e9\u00e1\u00fa\u00cd\u0173\u00e5\u00ea\u00e2\u0103\u0161\u010d\u1ebf\u1ec7\u00fc\u00e7\u03bb\u03bb\u03b7\u03bd\u03b9\u03ba\u03ac\u0431\u044a\u043b\u0433\u0430\u0440\u0441\u043a\u0438\u0050\u0443\u0441\u0441\u043a\u0438\u0439\u0421\u0440\u043f\u0441\u043a\u0438\u0423\u043a\u0440\u0430\u0457\u043d\u0441\u044c\u043a\u0430\ud55c\uad6d\uc5b4\u4e2d\u6587\u666e\u901a\u8bdd\u0028\u4e2d\u56fd\u5927\u9646\u0029\u666e\u901a\u8bdd\u0028\u9999\u6e2f\u0029\u4e2d\u6587\u0028\u53f0\u7063\u0029\u7cb5\u8a9e\u0028\u9999\u6e2f\u0029\u65e5\u672c\u8a9e\u0939\u093f\u0928\u094d\u0926\u0940\u0e20\u0e32\u0e29\u0e32\u0e44\u0e17\u0e22')
62136213

62146214
def test_funcptr_import_type(self):
62156215
self.emcc_args += ['--js-library', test_file('core/test_funcptr_import_type.js')]

tests/unicode_library.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
mergeInto(LibraryManager.library, {
22
printey: function() {
3-
out('Unicode snowman ☃ says hello!');
3+
out('Unicode snowman ☃ says hello! àČšñéáúÍųåêâăščếệüçλληνικάбългарскиPусскийСрпскиУкраїнська한국어中文普通话(中国大陆)普通话(香港)中文(台灣)粵語(香港)日本語हिन्दीภาษาไทย');
44
}
55
});

tools/utils.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def is_exe(fpath):
7373

7474
def read_file(file_path):
7575
"""Read from a file opened in text mode"""
76-
with open(file_path) as fh:
76+
with open(file_path, encoding='utf-8') as fh:
7777
return fh.read()
7878

7979

@@ -85,7 +85,7 @@ def read_binary(file_path):
8585

8686
def write_file(file_path, text):
8787
"""Write to a file opened in text mode"""
88-
with open(file_path, 'w') as fh:
88+
with open(file_path, 'w', encoding='utf-8') as fh:
8989
fh.write(text)
9090

9191

0 commit comments

Comments
 (0)