Work fork of an Android Jabber client for bridge users git.sr.ht/~singpolyma/cheogram-android
sopranica sgx xmpp jabber
0

Configure Feed

Select the types of activity you want to include in your feed.

Don't linkify invalid links

Amolith (Apr 4, 2026, 8:47 PM -0600) 7f45ef53 9ddb808f

+51
+14
src/main/java/de/gultsch/common/Linkify.java
··· 45 45 import eu.siacs.conversations.utils.StylingHelper; 46 46 import eu.siacs.conversations.utils.XmppUri; 47 47 import eu.siacs.conversations.xmpp.Jid; 48 + import java.net.URI; 49 + import java.net.URISyntaxException; 48 50 import java.util.Arrays; 49 51 import java.util.List; 50 52 import java.util.Objects; ··· 59 61 if (scheme == null) { 60 62 return false; 61 63 } 64 + if (!isValidUri(match)) { 65 + return false; 66 + } 62 67 return switch (scheme) { 63 68 case "tel" -> Patterns.URI_TEL.matcher(match).matches(); 64 69 case "http", "https" -> Patterns.URI_HTTP.matcher(match).matches(); ··· 75 80 } 76 81 default -> true; 77 82 }; 83 + } 84 + 85 + private static boolean isValidUri(final String match) { 86 + try { 87 + new URI(match); 88 + return true; 89 + } catch (final URISyntaxException e) { 90 + return false; 91 + } 78 92 } 79 93 80 94 public static void addLinks(final Spannable body) {
+37
src/test/java/de/gultsch/common/LinkifyTest.java
··· 1 + package de.gultsch.common; 2 + 3 + import org.junit.Assert; 4 + import org.junit.Test; 5 + 6 + public class LinkifyTest { 7 + 8 + @Test 9 + public void malformedEscapeIsRejected() { 10 + final var links = Linkify.getLinks("https://example.com/?x=%"); 11 + 12 + Assert.assertTrue(links.isEmpty()); 13 + } 14 + 15 + @Test 16 + public void validEscapesStillProduceLinks() { 17 + final var links = Linkify.getLinks("https://example.com/?x=%20"); 18 + 19 + Assert.assertEquals(1, links.size()); 20 + Assert.assertEquals("https://example.com/?x=%20", links.get(0).getRaw()); 21 + } 22 + 23 + @Test 24 + public void ipv6HostsStillProduceLinks() { 25 + final var links = Linkify.getLinks("http://[::1]/foo"); 26 + 27 + Assert.assertEquals(1, links.size()); 28 + Assert.assertEquals("http://[::1]/foo", links.get(0).getRaw()); 29 + } 30 + 31 + @Test 32 + public void bracketsInPathAreRejected() { 33 + final var links = Linkify.getLinks("http://example.com/foo[bar]"); 34 + 35 + Assert.assertTrue(links.isEmpty()); 36 + } 37 + }