Hi,
Regarding the following source snippets:
|
final private static String XML_SPECIAL = "[&<>\"]"; |
|
|
|
final private static Pattern XML_SPECIAL_RE = Pattern.compile(XML_SPECIAL); |
|
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); |
|
} |
|
} |
Why is the " character is considered unsafe in the following context?
My usecase: I am processing Markdown, which is then processed using velocity. I rely on the fact that " is outputted as " and not as ".
I am parsing the following line of markdown (which is a function call in velocity)
$object.myfun("myString")
Expected:
$object.myfun("myString")
Actual:
$object.myfun("myString")
Sources that this is valid:
Workaround:
I am currently setting the XML_SPECIAL_RE field with my own replacer, which ignores the "case.
Proposed solution:
|
appendable.append(Escaping.escapeHtml(s, false)); |
Thanks for your time!
Hi,
Regarding the following source snippets:
flexmark-java/flexmark-util-sequence/src/main/java/com/vladsch/flexmark/util/sequence/Escaping.java
Lines 43 to 45 in c0313d6
flexmark-java/flexmark-util-sequence/src/main/java/com/vladsch/flexmark/util/sequence/Escaping.java
Lines 64 to 78 in c0313d6
Why is the
"character is considered unsafe in the following context?My usecase: I am processing Markdown, which is then processed using velocity. I rely on the fact that
"is outputted as"and not as".I am parsing the following line of markdown (which is a function call in velocity)
Expected:
Actual:
Sources that this is valid:
"is not allowed in attribute, but says nothing about plain text)Workaround:
I am currently setting the
XML_SPECIAL_REfield with my own replacer, which ignores the"case.Proposed solution:
flexmark-java/flexmark-util-html/src/main/java/com/vladsch/flexmark/util/html/HtmlAppendableBase.java
Line 128 in c0313d6
Thanks for your time!