From 3655294170ef1a517ae6608b88605b0605bd3e12 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 29 Apr 2011 07:22:25 +0200 Subject: [PATCH] Filter texts when inserting them, not when parsing. --- .../java/net/pterodactylus/sone/text/FreenetLinkParser.java | 12 ------------ src/main/java/net/pterodactylus/sone/web/CreatePostPage.java | 2 ++ .../net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java | 2 ++ 3 files changed, 4 insertions(+), 12 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/text/FreenetLinkParser.java b/src/main/java/net/pterodactylus/sone/text/FreenetLinkParser.java index 4b88acc..7cb44ce 100644 --- a/src/main/java/net/pterodactylus/sone/text/FreenetLinkParser.java +++ b/src/main/java/net/pterodactylus/sone/text/FreenetLinkParser.java @@ -127,18 +127,6 @@ public class FreenetLinkParser implements Parser { } 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@"); diff --git a/src/main/java/net/pterodactylus/sone/web/CreatePostPage.java b/src/main/java/net/pterodactylus/sone/web/CreatePostPage.java index 57eb18a..147e4ae 100644 --- a/src/main/java/net/pterodactylus/sone/web/CreatePostPage.java +++ b/src/main/java/net/pterodactylus/sone/web/CreatePostPage.java @@ -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); } diff --git a/src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java b/src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java index eff7c41..0fc1236 100644 --- a/src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java +++ b/src/main/java/net/pterodactylus/sone/web/ajax/CreatePostAjaxPage.java @@ -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); } -- 2.7.4