aboutsummaryrefslogtreecommitdiff
path: root/src/main/java/com/juick/util
diff options
context:
space:
mode:
Diffstat (limited to 'src/main/java/com/juick/util')
-rw-r--r--src/main/java/com/juick/util/MessageUtils.java12
1 files changed, 7 insertions, 5 deletions
diff --git a/src/main/java/com/juick/util/MessageUtils.java b/src/main/java/com/juick/util/MessageUtils.java
index 3651540e..a04dc24f 100644
--- a/src/main/java/com/juick/util/MessageUtils.java
+++ b/src/main/java/com/juick/util/MessageUtils.java
@@ -68,7 +68,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;))*)([\\]\\}]|&gt;)");
+ private final static Pattern regexLinks2 = Pattern.compile("((?<=\\s)|(?<=\\A))([\\[{])((?:ht|f)tps?://(?:www\\.)?([^/\\s\")!&gt;]*)/?(?:[^]}](?<!&gt;))*)([]}])");
private final static String replyNumberRegex = "((?<=\\s)|(?<=\\A))\\/(\\d+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))";
@@ -82,10 +82,10 @@ public class MessageUtils {
private final static String ridRegex = "((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))#(\\d+)/(\\d+)((?=\\s)|(?=\\Z)|(?=\\p{Punct}))";
- private final static String textUrlRegex = "\\[([^\\]]+)\\]\\[((?:ht|f)tps?://[^\\]]+)\\]";
-
- private final static String textUrlRegex2 = "\\[([^\\]]+)\\]\\(((?:ht|f)tps?://[^\\)]+)\\)";
+ private final static String textUrlRegex = "\\[([^]]+)]\\[((?:ht|f)tps?://[^]]+)]";
+ private final static String textUrlRegex2 = "\\[([^]]+)]\\(((?:ht|f)tps?://[^)]+)\\)";
+ private final static String pidginUrlRegex = "(\\S+)\\s&lt;((?:ht|f)tps?://[^&]+)&gt;";
private final static String boldRegex = "((?<=\\s)|(?<=\\A)|(?<=\\p{Punct}))\\*([^\\*\\n<>]+)\\*((?=\\s)|(?=\\Z)|(?=\\p{Punct}))";
private final static String italicRegex = "((?<=\\s)|(?<=\\A))/([^\\/\\n<>]+)/((?=\\s)|(?=\\Z)|(?=\\p{Punct}))";
@@ -169,9 +169,11 @@ public class MessageUtils {
// [link text][http://juick.com/last?page=2]
// [link text](http://juick.com/last?page=2)
+ // www.juick.com <http://juick.com/>
// <a href="http://juick.com/last?page=2" rel="nofollow">link text</a>
msg = msg.replaceAll(textUrlRegex, "<a href=\"$2\" rel=\"nofollow\">$1</a>");
msg = msg.replaceAll(textUrlRegex2, "<a href=\"$2\" rel=\"nofollow\">$1</a>");
+ msg = msg.replaceAll(pidginUrlRegex, "<a href=\"$2\" rel=\"nofollow\">$1</a>");
// #12345
// <a href="http://juick.com/12345">#12345</a>
@@ -218,7 +220,7 @@ public class MessageUtils {
Matcher m = regexLinks2.matcher(msg);
StringBuffer sb = new StringBuffer();
while (m.find()) {
- String url = m.group(3).replace(" ", "%20").replaceAll("\\s+", StringUtils.EMPTY);
+ String url = m.group(3).replace(" ", "%20").replace("$", "%36").replaceAll("\\s+", StringUtils.EMPTY);
m.appendReplacement(sb, "$1$2<a href=\"" + url + "\" rel=\"nofollow\">$4</a>$5");
}
m.appendTail(sb);