aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick
diff options
context:
space:
mode:
authorGravatar Vitaly Takmazov2018-11-12 13:31:17 +0300
committerGravatar Vitaly Takmazov2018-11-12 13:31:17 +0300
commit830f62be6710265d4731276eeddf001fc3e0f80d (patch)
tree77f48ddbaf614b357914a0bf8a47814c2ba4861c /src/main/java/com/juick
parent0020a6561f537db248cff6630346bde8f20aaa1f (diff)
parse entities before html escaping
Diffstat (limited to 'src/main/java/com/juick')
-rw-r--r--src/main/java/com/juick/util/MessageUtils.java11
1 files changed, 5 insertions, 6 deletions
diff --git a/src/main/java/com/juick/util/MessageUtils.java b/src/main/java/com/juick/util/MessageUtils.java
index 8db8148c..4d31a6cd 100644
--- a/src/main/java/com/juick/util/MessageUtils.java
+++ b/src/main/java/com/juick/util/MessageUtils.java
@@ -63,7 +63,7 @@ public class MessageUtils {
private final static String urlWithWhitespacesRegex =
urlWhiteSpacePrefix + urlRegex;
- private final static Pattern regexLinks2 = Pattern.compile("((?<=\\s)|(?<=\\A))([\\[\\{]|&lt;)((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\\"\\)\\!]+)/?(?:[^\\]\\}](?<!&gt;))*)([\\]\\}]|&gt;)");
+ private final static Pattern regexLinks2 = Pattern.compile("((?<=\\s)|(?<=\\A))([\\[\\{]|&lt;)((?:ht|f)tps?://(?:www\\.)?([^\\/\\s\\\"\\)\\!]+)/?(?:[^\\]\\}](?<!\\>))*)([\\]\\}]|\\>)");
private final static String replyNumberRegex = "((?<=\\s)|(?<=\\A))\\/(\\d+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))";
@@ -87,7 +87,7 @@ public class MessageUtils {
private final static String underlineRegex = "((?<=\\s)|(?<=\\A))_([^\\_\\n<>]+)_((?=\\s)|(?=\\Z)|(?=\\p{Punct}))";
- private final static String citateRegex = "(?:(?<=\\n)|(?<=\\A))&gt; *(.*)?(\\n|(?=\\Z))";
+ private final static String citateRegex = "(?:(?<=\\n)|(?<=\\A))\\> *(.*)?(\\n|(?=\\Z))";
public static List<Entity> getEntities(Message msg) {
@@ -144,10 +144,6 @@ public class MessageUtils {
}
public static String formatMessage(String msg) {
- msg = msg.replaceAll("&", "&amp;");
- msg = msg.replaceAll("<", "&lt;");
- msg = msg.replaceAll(">", "&gt;");
-
// --
// &mdash;
msg = msg.replaceAll("((?<=\\s)|(?<=\\A))\\-\\-?((?=\\s)|(?=\\Z))", "$1&mdash;$2");
@@ -209,6 +205,9 @@ public class MessageUtils {
msg = msg.replaceAll(citateRegex, "<q>$1</q>");
msg = msg.replaceAll("</q><q>", "\n");
+ msg = msg.replaceAll("&", "&amp;");
+ msg = msg.replaceAll("<", "&lt;");
+ msg = msg.replaceAll(">", "&gt;");
msg = msg.replaceAll("\n", "<br/>\n");
return msg;
}