From a5a01001dea42270864ba51345f323d710602f0b Mon Sep 17 00:00:00 2001 From: =?utf8?q?David=20=E2=80=98Bombe=E2=80=99=20Roden?= Date: Thu, 6 Jan 2011 14:39:08 +0100 Subject: [PATCH] =?utf8?q?Don=E2=80=99t=20add=20a=20link=20if=20an=20SSK?= =?utf8?q?=20or=20a=20USK=20fail=20parsing.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- .../net/pterodactylus/sone/text/FreenetLinkParser.java | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/src/main/java/net/pterodactylus/sone/text/FreenetLinkParser.java b/src/main/java/net/pterodactylus/sone/text/FreenetLinkParser.java index 24eac3b..fbf87c8 100644 --- a/src/main/java/net/pterodactylus/sone/text/FreenetLinkParser.java +++ b/src/main/java/net/pterodactylus/sone/text/FreenetLinkParser.java @@ -21,6 +21,7 @@ import java.io.BufferedReader; import java.io.IOException; import java.io.Reader; import java.io.StringReader; +import java.net.MalformedURLException; import java.util.logging.Level; import java.util.logging.Logger; import java.util.regex.Matcher; @@ -29,6 +30,7 @@ import java.util.regex.Pattern; import net.pterodactylus.sone.data.Sone; import net.pterodactylus.util.logging.Logging; import net.pterodactylus.util.template.TemplateFactory; +import freenet.keys.FreenetURI; /** * {@link Parser} implementation that can recognize Freenet URIs. @@ -185,9 +187,17 @@ public class FreenetLinkParser implements Parser { } boolean fromPostingSone = false; if ((linkType == LinkType.SSK) || (linkType == LinkType.USK)) { - fromPostingSone = link.substring(4, 47).equals(postingSone.getId()); + try { + new FreenetURI(link); + fromPostingSone = link.substring(4, 47).equals(postingSone.getId()); + parts.add(fromPostingSone ? createTrustedFreenetLinkPart(link, name) : createFreenetLinkPart(link, name)); + } catch (MalformedURLException mue1) { + /* it’s not a valid link. */ + parts.add(createPlainTextPart(link)); + } + } else { + parts.add(fromPostingSone ? createTrustedFreenetLinkPart(link, name) : createFreenetLinkPart(link, name)); } - parts.add(fromPostingSone ? createTrustedFreenetLinkPart(link, name) : createFreenetLinkPart(link, name)); } else if ((linkType == LinkType.HTTP) || (linkType == LinkType.HTTPS)) { name = link.substring(linkType == LinkType.HTTP ? 7 : 8); int firstSlash = name.indexOf('/'); -- 2.7.4