From d2a7e642f7740f0dcb4ab1fb108b4f162d0572d8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jukka=20Jyl=C3=A4nki?= Date: Thu, 15 Oct 2015 16:43:25 +0300 Subject: [PATCH 1/3] Fix memory string initializer to generate format that is safe for text files on Windows. --- tools/eliminator/node_modules/uglify-js/lib/process.js | 3 ++- tools/shared.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/tools/eliminator/node_modules/uglify-js/lib/process.js b/tools/eliminator/node_modules/uglify-js/lib/process.js index d75ab18aa474f..8f94ce3452b63 100644 --- a/tools/eliminator/node_modules/uglify-js/lib/process.js +++ b/tools/eliminator/node_modules/uglify-js/lib/process.js @@ -1365,7 +1365,8 @@ function make_string(str, ascii_only) { }; function to_ascii(str) { - return str.replace(/[\u0080-\uffff]/g, function(ch) { + // Escape the ^Z (= 0x1a = substitute) ASCII character and all characters higher than 7-bit ASCII. + return str.replace(/[\u001a\u0080-\uffff]/g, function(ch) { var code = ch.charCodeAt(0).toString(16); while (code.length < 4) code = "0" + code; return "\\u" + code; diff --git a/tools/shared.py b/tools/shared.py index c583e27074b47..59a5d411003bc 100644 --- a/tools/shared.py +++ b/tools/shared.py @@ -1938,8 +1938,9 @@ def generate_string_initializer(s): s = ''.join(map(chr, s)) s = s.replace('\\', '\\\\').replace("'", "\\'") s = s.replace('\n', '\\n').replace('\r', '\\r') + # Escape the ^Z (= 0x1a = substitute) ASCII character and all characters higher than 7-bit ASCII. def escape(x): return '\\x{:02x}'.format(ord(x.group())) - return re.sub('[\x80-\xff]', escape, s) + return re.sub('[\x1a\x80-\xff]', escape, s) def execute(cmd, *args, **kw): try: From a76176875846b7c3b898d27f255337ee164d67af Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jukka=20Jyl=C3=A4nki?= Date: Mon, 25 Jan 2016 20:54:09 +0200 Subject: [PATCH 2/3] Improve tools/line_endings.py to show counts and locations of mismatched line endings. --- tools/line_endings.py | 18 ++++++++++++++++-- 1 file changed, 16 insertions(+), 2 deletions(-) diff --git a/tools/line_endings.py b/tools/line_endings.py index 325ea32596c3f..1bef0d08ffaf2 100644 --- a/tools/line_endings.py +++ b/tools/line_endings.py @@ -24,16 +24,30 @@ def check_line_endings(filename, print_errors=True): has_dos_line_endings = False has_unix_line_endings = False + dos_line_ending_example = '' + dos_line_ending_count = 0 + unix_line_ending_example = '' + unix_line_ending_count = 0 if '\r\n' in data: + dos_line_ending_example = data[max(0, data.find('\r\n') - 50):min(len(data), data.find('\r\n')+50)].replace('\r', '\\r').replace('\n', '\\n') + dos_line_ending_count = data.count('\r\n') has_dos_line_endings = True data = data.replace('\r\n', 'A') # Replace all DOS line endings with some other character, and continue testing what's left. if '\n' in data: + unix_line_ending_example = data[max(0, data.find('\n') - 50):min(len(data), data.find('\n')+50)].replace('\r', '\\r').replace('\n', '\\n') + unix_line_ending_count = data.count('\n') has_unix_line_endings = True if '\r' in data: - if print_errors: print >> sys.stderr, 'File \'' + filename + '\' contains OLD OSX line endings "\\r"' + old_osx_line_ending_example = data[max(0, data.find('\r') - 50):min(len(data), data.find('\r')+50)].replace('\r', '\\r').replace('\n', '\\n') + if print_errors: + print >> sys.stderr, 'File \'' + filename + '\' contains OLD OSX line endings "\\r"' + print >> sys.stderr, "Content around an OLD OSX line ending location: '" + old_osx_line_ending_example + "'" return 1 # Return a non-zero process exit code since we don't want to use the old OSX (9.x) line endings anywhere. if has_dos_line_endings and has_unix_line_endings: - if print_errors: print >> sys.stderr, 'File \'' + filename + '\' contains both DOS "\\r\\n" and UNIX "\\n" line endings!' + if print_errors: + print >> sys.stderr, 'File \'' + filename + '\' contains both DOS "\\r\\n" and UNIX "\\n" line endings! (' + str(dos_line_ending_count) + ' DOS line endings, ' + str(unix_line_ending_count) + ' UNIX line endings)' + print >> sys.stderr, "Content around a DOS line ending location: '" + dos_line_ending_example + "'" + print >> sys.stderr, "Content around an UNIX line ending location: '" + unix_line_ending_example + "'" return 1 # Mixed line endings else: return 0 From 17f8dd91bd8ba2cb0b72f24c03edc980a95d7637 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jukka=20Jyl=C3=A4nki?= Date: Tue, 26 Jan 2016 02:47:00 +0200 Subject: [PATCH 3/3] Clarify Emscripten specific localmod comment. --- tools/eliminator/node_modules/uglify-js/lib/process.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/tools/eliminator/node_modules/uglify-js/lib/process.js b/tools/eliminator/node_modules/uglify-js/lib/process.js index 8f94ce3452b63..37b0462848e8b 100644 --- a/tools/eliminator/node_modules/uglify-js/lib/process.js +++ b/tools/eliminator/node_modules/uglify-js/lib/process.js @@ -1365,7 +1365,8 @@ function make_string(str, ascii_only) { }; function to_ascii(str) { - // Escape the ^Z (= 0x1a = substitute) ASCII character and all characters higher than 7-bit ASCII. + // XXX Emscripten: escape the ^Z (= 0x1a = substitute) ASCII character in addition to the extended ASCII characters, + // since otherwise opening the generated file on Windows in ASCII mode gives trouble. return str.replace(/[\u001a\u0080-\uffff]/g, function(ch) { var code = ch.charCodeAt(0).toString(16); while (code.length < 4) code = "0" + code;