Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for vsch/flexmark-java#435 #480

Merged
merged 1 commit into from
Jan 24, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);

Expand All @@ -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("&amp;");
} else if (s.equals("<")) {
sb.append("&lt;");
} else if (s.equals(">")) {
sb.append("&gt;");
} else if (s.equals("\"")) {
sb.append("&quot;");
} else {
sb.append(s);
switch (s) {
case "&":
sb.append("&amp;");
break;
case "<":
sb.append("&lt;");
break;
case ">":
sb.append("&gt;");
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("&amp;", BasedSequence.NULL));
} else if (s1.equals("<")) {
textMapper.addReplacedText(startIndex, endIndex, PrefixedSubSequence.prefixOf("&lt;", BasedSequence.NULL));
} else if (s1.equals(">")) {
textMapper.addReplacedText(startIndex, endIndex, PrefixedSubSequence.prefixOf("&gt;", BasedSequence.NULL));
} else if (s1.equals("\"")) {
textMapper.addReplacedText(startIndex, endIndex, PrefixedSubSequence.prefixOf("&quot;", BasedSequence.NULL));
} else {
textMapper.addOriginalText(startIndex, endIndex);
switch (s1) {
case "&":
textMapper.addReplacedText(startIndex, endIndex, PrefixedSubSequence.prefixOf("&amp;", BasedSequence.NULL));
break;
case "<":
textMapper.addReplacedText(startIndex, endIndex, PrefixedSubSequence.prefixOf("&lt;", BasedSequence.NULL));
break;
case ">":
textMapper.addReplacedText(startIndex, endIndex, PrefixedSubSequence.prefixOf("&gt;", BasedSequence.NULL));
break;
default:
textMapper.addOriginalText(startIndex, endIndex);
break;
}
}
};
Expand Down