Skip to content

Commit 63db282

Browse files
authored
Properly specify UTF8 in tests and when dealing with Closure (#25134)
This is from earlier PR #21478
1 parent a3b40ee commit 63db282

File tree

2 files changed

+8
-2
lines changed

2 files changed

+8
-2
lines changed

test/test_browser.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3409,10 +3409,12 @@ def test_modularize(self, args, code, opts):
34093409
# this test is synchronous, so avoid async startup due to wasm features
34103410
self.compile_btest('browser_test_hello_world.c', ['-sMODULARIZE', '-sSINGLE_FILE'] + args + opts)
34113411
create_file('a.html', '''
3412+
<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"></head><body>
34123413
<script src="a.out.js"></script>
34133414
<script>
34143415
%s
34153416
</script>
3417+
</body></html>
34163418
''' % code)
34173419
self.run_browser('a.html', '/report_result?0')
34183420

@@ -4827,7 +4829,7 @@ def test_single_file_locate_file(self):
48274829
# Tests that SINGLE_FILE works as intended in a Worker in JS output
48284830
def test_single_file_worker_js(self):
48294831
self.compile_btest('browser_test_hello_world.c', ['-o', 'test.js', '--proxy-to-worker', '-sSINGLE_FILE'])
4830-
create_file('test.html', '<script src="test.js"></script>')
4832+
create_file('test.html', '<!DOCTYPE html><html lang="en"><head><meta charset="utf-8"></head><body><script src="test.js"></script></body></html>')
48314833
self.run_browser('test.html', '/report_result?0')
48324834
self.assertExists('test.js')
48334835
self.assertNotExists('test.worker.js')

tools/building.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -609,6 +609,9 @@ def closure_compiler(filename, advanced=True, extra_closure_args=None):
609609
# Tell closure never to inject the 'use strict' directive.
610610
args += ['--emit_use_strict=false']
611611
args += ['--assume_static_inheritance_is_not_used=false']
612+
# Always output UTF-8 files, this helps generate UTF-8 code points instead of escaping code points with \uxxxx inside strings.
613+
# Closure outputs ASCII by default, and must be adjusted to output UTF8 (https://github.com/google/closure-compiler/issues/4158)
614+
args += ['--charset=UTF8']
612615

613616
if settings.IGNORE_CLOSURE_COMPILER_ERRORS:
614617
args.append('--jscomp_off=*')
@@ -669,7 +672,8 @@ def move_to_safe_7bit_ascii_filename(filename):
669672
# 7-bit ASCII range. Therefore make sure the command line we pass does not contain any such
670673
# input files by passing all input filenames relative to the cwd. (user temp directory might
671674
# be in user's home directory, and user's profile name might contain unicode characters)
672-
proc = run_process(cmd, stderr=PIPE, check=False, env=env, cwd=tempfiles.tmpdir)
675+
# https://github.com/google/closure-compiler/issues/4159: Closure outputs stdout/stderr in iso-8859-1 on Windows.
676+
proc = run_process(cmd, stderr=PIPE, check=False, env=env, cwd=tempfiles.tmpdir, encoding='iso-8859-1' if WINDOWS else 'utf-8')
673677

674678
# XXX Closure bug: if Closure is invoked with --create_source_map, Closure should create a
675679
# outfile.map source map file (https://github.com/google/closure-compiler/wiki/Source-Maps)

0 commit comments

Comments
 (0)