diff options
author | Vitaly Takmazov | 2019-01-22 20:52:52 +0300 |
---|---|---|
committer | Vitaly Takmazov | 2019-01-22 20:52:52 +0300 |
commit | 0b418caf401c53eb73721a324cd13041c185d0fb (patch) | |
tree | 4af4d2b8b7a47db07c98299bbc6dbced3713f125 | |
parent | dd7b6d46a7d0efd7198415b6bcc3e86e1d921821 (diff) |
Fix quote regex
-rw-r--r-- | src/main/java/com/juick/util/MessageUtils.java | 10 | ||||
-rw-r--r-- | src/test/java/com/juick/MessageTest.java | 9 |
2 files changed, 13 insertions, 6 deletions
diff --git a/src/main/java/com/juick/util/MessageUtils.java b/src/main/java/com/juick/util/MessageUtils.java index 5cc8bb97..72c9bd04 100644 --- a/src/main/java/com/juick/util/MessageUtils.java +++ b/src/main/java/com/juick/util/MessageUtils.java @@ -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))\\> *(.*)?(\\n|(?=\\Z))"; + private final static String citateRegex = "(?:(?<=\\n)|(?<=\\A))> *(.*)?(\\n|(?=\\Z))"; public static List<Entity> getEntities(Message msg) { @@ -144,14 +144,12 @@ public class MessageUtils { } public static String formatMessage(String msg) { - // > citate - msg = msg.replaceAll(citateRegex, "<q>$1</q>"); - msg = msg.replaceAll("</q><q>", "\n"); - - msg = msg.replaceAll("&", "&"); msg = msg.replaceAll("<", "<"); msg = msg.replaceAll(">", ">"); + // > citate + msg = msg.replaceAll(citateRegex, "<q>$1</q>"); + msg = msg.replaceAll("</q><q>", "\n"); // -- // — msg = msg.replaceAll("((?<=\\s)|(?<=\\A))\\-\\-?((?=\\s)|(?=\\Z))", "$1—$2"); diff --git a/src/test/java/com/juick/MessageTest.java b/src/test/java/com/juick/MessageTest.java index 2d12a3df..0b48efa1 100644 --- a/src/test/java/com/juick/MessageTest.java +++ b/src/test/java/com/juick/MessageTest.java @@ -206,4 +206,13 @@ public class MessageTest { Remark remark = new Remark(options); String parsed = remark.convertFragment(text); } + @Test + public void messageFormatTest() { + String msg = "> quote\nmessage"; + assertThat(MessageUtils.formatMessage(msg), is("<q>quote</q>message")); + String brokenComment = "<!-- read next"; + assertThat(MessageUtils.formatMessage(brokenComment), is("<!-- read next")); + String url = "[ya](http://ya.ru)"; + assertThat(MessageUtils.formatMessage(url), is("<a href=\"http://ya.ru\" rel=\"nofollow\">ya</a>")); + } } |