Skip to content

Commit

Permalink
[ggj][engx] fix: use singleton in HtmlEscaper (#272)
Browse files Browse the repository at this point in the history
* fix: use singleton in HtmlEscaper

* fix: linter

* fix: merge
  • Loading branch information
miraleung authored Sep 4, 2020
1 parent e78504d commit 155aeb2
Showing 1 changed file with 5 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,10 +18,12 @@
import com.google.common.escape.Escapers;

public class HtmlEscaper extends Escaper {
private static final HtmlEscaper SINGLETON = new HtmlEscaper();

// Based on the observation of the generated java files, we escape the following
// five characters by html escaper. We do not directly use guava HtmlEscapers here because
// it only escapes`<>&\"'` as specified by HTML 4.01.
private static final Escaper escaper =
private static final Escaper charEscaper =
Escapers.builder()
.addEscape('<', "&lt;")
.addEscape('>', "&gt;")
Expand All @@ -34,10 +36,10 @@ private HtmlEscaper() {}

@Override
public String escape(String sourceString) {
return escaper.escape(sourceString);
return charEscaper.escape(sourceString);
}

public static String escaper(String source) {
return new HtmlEscaper().escape(source);
return SINGLETON.escape(source);
}
}

0 comments on commit 155aeb2

Please sign in to comment.