diff --git a/flexmark-util-sequence/src/main/java/com/vladsch/flexmark/util/sequence/Escaping.java b/flexmark-util-sequence/src/main/java/com/vladsch/flexmark/util/sequence/Escaping.java index 5b4c4562d..d8b6fc551 100644 --- a/flexmark-util-sequence/src/main/java/com/vladsch/flexmark/util/sequence/Escaping.java +++ b/flexmark-util-sequence/src/main/java/com/vladsch/flexmark/util/sequence/Escaping.java @@ -14,7 +14,7 @@ public class Escaping { // pure chars not for pattern - final public static String ESCAPABLE_CHARS = "\"#$%&'()*+,./:;<=>?@[]\\^_`{|}~-"; + final public static String ESCAPABLE_CHARS = "#$%&'()*+,./:;<=>?@[]\\^_`{|}~-"; final public static String ESCAPABLE = "[!" + ESCAPABLE_CHARS @@ -40,7 +40,7 @@ public class Escaping { final private static Pattern ENTITY_ONLY = Pattern.compile(ENTITY, Pattern.CASE_INSENSITIVE); - final private static String XML_SPECIAL = "[&<>\"]"; + final private static String XML_SPECIAL = "[&<>]"; final private static Pattern XML_SPECIAL_RE = Pattern.compile(XML_SPECIAL); @@ -64,32 +64,38 @@ public class Escaping { final private static Replacer UNSAFE_CHAR_REPLACER = new Replacer() { @Override public void replace(@NotNull String s, @NotNull StringBuilder sb) { - if (s.equals("&")) { - sb.append("&"); - } else if (s.equals("<")) { - sb.append("<"); - } else if (s.equals(">")) { - sb.append(">"); - } else if (s.equals("\"")) { - sb.append("""); - } else { - sb.append(s); + switch (s) { + case "&": + sb.append("&"); + break; + case "<": + sb.append("<"); + break; + case ">": + sb.append(">"); + break; + default: + sb.append(s); + break; } } @Override public void replace(@NotNull BasedSequence original, int startIndex, int endIndex, @NotNull ReplacedTextMapper textMapper) { String s1 = original.subSequence(startIndex, endIndex).toString(); - if (s1.equals("&")) { - textMapper.addReplacedText(startIndex, endIndex, PrefixedSubSequence.prefixOf("&", BasedSequence.NULL)); - } else if (s1.equals("<")) { - textMapper.addReplacedText(startIndex, endIndex, PrefixedSubSequence.prefixOf("<", BasedSequence.NULL)); - } else if (s1.equals(">")) { - textMapper.addReplacedText(startIndex, endIndex, PrefixedSubSequence.prefixOf(">", BasedSequence.NULL)); - } else if (s1.equals("\"")) { - textMapper.addReplacedText(startIndex, endIndex, PrefixedSubSequence.prefixOf(""", BasedSequence.NULL)); - } else { - textMapper.addOriginalText(startIndex, endIndex); + switch (s1) { + case "&": + textMapper.addReplacedText(startIndex, endIndex, PrefixedSubSequence.prefixOf("&", BasedSequence.NULL)); + break; + case "<": + textMapper.addReplacedText(startIndex, endIndex, PrefixedSubSequence.prefixOf("<", BasedSequence.NULL)); + break; + case ">": + textMapper.addReplacedText(startIndex, endIndex, PrefixedSubSequence.prefixOf(">", BasedSequence.NULL)); + break; + default: + textMapper.addOriginalText(startIndex, endIndex); + break; } } };