From d11409a9e2c072ad69be7d19f1fe715cafae0a65 Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Fri, 21 Dec 2012 07:40:56 +0100 Subject: [PATCH] Encode URLs correctly when creating an external link. --- src/main/java/net/pterodactylus/sone/template/ParserFilter.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java index d6b64ba..b8af831 100644 --- a/src/main/java/net/pterodactylus/sone/template/ParserFilter.java +++ b/src/main/java/net/pterodactylus/sone/template/ParserFilter.java @@ -20,7 +20,9 @@ package net.pterodactylus.sone.template; import java.io.IOException; import java.io.StringReader; import java.io.StringWriter; +import java.io.UnsupportedEncodingException; import java.io.Writer; +import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; import java.util.Map; @@ -213,7 +215,12 @@ public class ParserFilter implements Filter { * The part to render */ private void render(Writer writer, LinkPart linkPart) { - renderLink(writer, "/external-link/?_CHECKED_HTTP_=" + linkPart.getLink(), linkPart.getText(), linkPart.getTitle(), "internet"); + try { + renderLink(writer, "/external-link/?_CHECKED_HTTP_=" + URLEncoder.encode(linkPart.getLink(), "UTF-8"), linkPart.getText(), linkPart.getTitle(), "internet"); + } catch (UnsupportedEncodingException uee1) { + /* not possible for UTF-8. */ + throw new RuntimeException("The JVM does not support UTF-8 encoding!", uee1); + } } /** -- 2.7.4