From 7d58cb3ab672823d74c1a6b9299c8bb1b60d6049 Mon Sep 17 00:00:00 2001 From: goktug Date: Fri, 21 Dec 2018 11:50:59 -0800 Subject: [PATCH] Makes UTF8 BOM removal in SourceFile unconditional Some of the callers were incorrect and was already passing true unconditionally which is the behavior introduced by this CL explicitly. ------------- Created by MOE: https://github.com/google/moe MOE_MIGRATED_REVID=226521027 --- .../google/javascript/jscomp/SourceFile.java | 18 ++++++------------ 1 file changed, 6 insertions(+), 12 deletions(-) diff --git a/src/com/google/javascript/jscomp/SourceFile.java b/src/com/google/javascript/jscomp/SourceFile.java index bad968cbc66..e43b08c72de 100644 --- a/src/com/google/javascript/jscomp/SourceFile.java +++ b/src/com/google/javascript/jscomp/SourceFile.java @@ -47,7 +47,6 @@ import java.util.Arrays; import java.util.Enumeration; import java.util.List; -import java.util.Objects; import java.util.zip.ZipEntry; import java.util.zip.ZipFile; @@ -173,15 +172,10 @@ String getCodeNoCache() { } void setCode(String sourceCode) { - this.setCode(sourceCode, false); - } - - void setCode(String sourceCode, boolean removeUtf8Bom) { - if (removeUtf8Bom && sourceCode != null && sourceCode.startsWith(UTF8_BOM)) { - code = sourceCode.substring(UTF8_BOM.length()); - } else { - code = sourceCode; - } + code = + sourceCode != null && sourceCode.startsWith(UTF8_BOM) + ? sourceCode.substring(UTF8_BOM.length()) + : sourceCode; resetLineOffsets(); } @@ -616,7 +610,7 @@ public synchronized String getCode() throws IOException { throw new IOException("Failed to read: " + path + ", is this input UTF-8 encoded?", e); } - super.setCode(cachedCode, Objects.equals(this.getCharset(), inputCharset)); + super.setCode(cachedCode); // Byte Order Mark can be removed by setCode cachedCode = super.getCode(); } @@ -724,7 +718,7 @@ public synchronized String getCode() throws IOException { // Must close the stream or else the cache won't be cleared. inputStream.close(); - super.setCode(cachedCode, Objects.equals(this.getCharset(), StandardCharsets.UTF_8)); + super.setCode(cachedCode); // Byte Order Mark can be removed by setCode cachedCode = super.getCode(); }