Skip to content

Commit

Permalink
Revert "Revert "Remove UTF-8 BOM from source files""
Browse files Browse the repository at this point in the history
This reverts commit 0b3c460.
  • Loading branch information
ChadKillingsworth committed Sep 25, 2015
1 parent 60ab7d6 commit a3895e1
Showing 1 changed file with 12 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/com/google/javascript/jscomp/SourceFile.java
Expand Up @@ -52,6 +52,7 @@
*/
public class SourceFile implements StaticSourceFile, Serializable {
private static final long serialVersionUID = 1L;
private static final String UTF8_BOM = String.format("%c", CommandLineRunner.UTF8_BOM_CODE);

/** A JavaScript source code provider. The value should
* be cached so that the source text stays consistent throughout a single
Expand Down Expand Up @@ -169,7 +170,15 @@ String getCodeNoCache() {
}

private void setCode(String sourceCode) {
code = sourceCode;
this.setCode(sourceCode, false);
}

private void setCode(String sourceCode, boolean removeUtf8Bom) {
if (removeUtf8Bom && sourceCode != null && sourceCode.startsWith(UTF8_BOM)) {
code = sourceCode.substring(UTF8_BOM.length());
} else {
code = sourceCode;
}
}

public String getOriginalPath() {
Expand Down Expand Up @@ -543,7 +552,7 @@ public synchronized String getCode() throws IOException {

if (cachedCode == null) {
cachedCode = Files.toString(file, this.getCharset());
super.setCode(cachedCode);
super.setCode(cachedCode, this.getCharset() == StandardCharsets.UTF_8);
}
return cachedCode;
}
Expand Down Expand Up @@ -636,7 +645,7 @@ public synchronized String getCode() throws IOException {

if (cachedCode == null) {
cachedCode = Resources.toString(url, this.getCharset());
super.setCode(cachedCode);
super.setCode(cachedCode, this.getCharset() == StandardCharsets.UTF_8);
}
return cachedCode;
}
Expand Down

0 comments on commit a3895e1

Please sign in to comment.