From: David ‘Bombe’ Roden Date: Fri, 29 Apr 2011 05:22:25 +0000 (+0200) Subject: Filter texts when inserting them, not when parsing. X-Git-Tag: 0.6.4^2~32 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=3655294170ef1a517ae6608b88605b0605bd3e12;p=Sone.git Filter texts when inserting them, not when parsing. --- 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); }