From: David ‘Bombe’ Roden Date: Fri, 21 Dec 2012 06:40:56 +0000 (+0100) Subject: Encode URLs correctly when creating an external link. X-Git-Tag: 0.8.5^2~9 X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=d11409a9e2c072ad69be7d19f1fe715cafae0a65;p=Sone.git Encode URLs correctly when creating an external link. --- 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); + } } /**