Filter texts when inserting them, not when parsing.
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 29 Apr 2011 05:22:25 +0000 (07:22 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Fri, 29 Apr 2011 05:22:25 +0000 (07:22 +0200)
src/main/java/net/pterodactylus/sone/text/FreenetLinkParser.java
src/main/java/net/pterodactylus/sone/web/CreatePostPage.java
src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java

index 4b88acc..7cb44ce 100644 (file)
@@ -127,18 +127,6 @@ public class FreenetLinkParser implements Parser<FreenetLinkParserContext> {
                        }
                        emptyLines = 0;
                        boolean lineComplete = true;
-
-                       /* filter http(s) links to own node. */
-                       String hostHeader = (context.getRequest() != null) ? context.getRequest().getHttpRequest().getHeader("host") : null;
-                       logger.log(Level.FINEST, "hostHeader: %s", hostHeader);
-                       if (hostHeader != null) {
-                               for (String toRemove : new String[] { "http://" + hostHeader + "/", "https://" + hostHeader + "/", "http://" + hostHeader, "https://" + hostHeader }) {
-                                       while (line.indexOf(toRemove) != -1) {
-                                               line = line.replace(toRemove, "");
-                                       }
-                               }
-                       }
-
                        while (line.length() > 0) {
                                int nextKsk = line.indexOf("KSK@");
                                int nextChk = line.indexOf("CHK@");
index 57eb18a..147e4ae 100644 (file)
@@ -19,6 +19,7 @@ package net.pterodactylus.sone.web;
 
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.text.TextFilter;
 import net.pterodactylus.sone.web.page.Page.Request.Method;
 import net.pterodactylus.util.template.Template;
 import net.pterodactylus.util.template.TemplateContext;
@@ -64,6 +65,7 @@ public class CreatePostPage extends SoneTemplatePage {
                                        sender = currentSone;
                                }
                                Sone recipient = webInterface.getCore().getSone(recipientId, false);
+                               text = TextFilter.filter(request.getHttpRequest().getHeader("host"), text);
                                webInterface.getCore().createPost(sender, recipient, System.currentTimeMillis(), text);
                                throw new RedirectException(returnPage);
                        }
index eff7c41..0fc1236 100644 (file)
@@ -19,6 +19,7 @@ package net.pterodactylus.sone.web.ajax;
 
 import net.pterodactylus.sone.data.Post;
 import net.pterodactylus.sone.data.Sone;
+import net.pterodactylus.sone.text.TextFilter;
 import net.pterodactylus.sone.web.WebInterface;
 import net.pterodactylus.util.json.JsonObject;
 
@@ -59,6 +60,7 @@ public class CreatePostAjaxPage extends JsonPage {
                if ((text == null) || (text.trim().length() == 0)) {
                        return createErrorJsonObject("text-required");
                }
+               text = TextFilter.filter(request.getHttpRequest().getHeader("host"), text);
                Post newPost = webInterface.getCore().createPost(sender, recipient, text);
                return createSuccessJsonObject().put("postId", newPost.getId()).put("sone", sender.getId()).put("recipient", (newPost.getRecipient() != null) ? newPost.getRecipient().getId() : null);
        }