Skip to content

Commit

Permalink
Makes UTF8 BOM removal in SourceFile unconditional
Browse files Browse the repository at this point in the history
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
  • Loading branch information
gkdn authored and brad4d committed Dec 26, 2018
1 parent 7937ec1 commit 7d58cb3
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/com/google/javascript/jscomp/SourceFile.java
Expand Up @@ -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;

Expand Down Expand Up @@ -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();
}

Expand Down Expand Up @@ -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();
}
Expand Down Expand Up @@ -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();
}
Expand Down

0 comments on commit 7d58cb3

Please sign in to comment.