From 0ec7a2d8ab803b0e2df2c616f61d2b69b042561f Mon Sep 17 00:00:00 2001 From: Alex Clayton Date: Mon, 21 Mar 2016 15:41:42 +0000 Subject: Don't allow JIDs with explicitly empty resources As per swiften patch of same name (6159c580884583bad0e17d4e96ea9ffc7e0be29a). A JID may have no resource, but may not have an empty resource. Mark such JIDs as invalid. Test-information: New unit test passes. Change-Id: I66ec7810ac29cb3963470b08f0d9f4901d2307f3 diff --git a/src/com/isode/stroke/jid/JID.java b/src/com/isode/stroke/jid/JID.java index 59eef52..8b62ca1 100644 --- a/src/com/isode/stroke/jid/JID.java +++ b/src/com/isode/stroke/jid/JID.java @@ -1,5 +1,5 @@ /* - * Copyright (c) 2010-2012, Isode Limited, London, England. + * Copyright (c) 2010-2016, Isode Limited, London, England. * All rights reserved. */ /* @@ -14,13 +14,13 @@ package com.isode.stroke.jid; -import com.isode.stroke.idn.ICUConverter; -import com.isode.stroke.idn.IDNConverter; -import com.ibm.icu.text.StringPrepParseException; -import com.isode.stroke.base.NotNull; import java.util.Arrays; import java.util.List; +import com.isode.stroke.base.NotNull; +import com.isode.stroke.idn.ICUConverter; +import com.isode.stroke.idn.IDNConverter; + /** * JID helper. * @@ -147,6 +147,9 @@ public class JID implements Comparable { NotNull.exceptIfNull(domain, "domain"); valid_ = true; hasResource_ = (resource != null); + if (hasResource_ && resource.isEmpty()) { + valid_ = false; + } nameprepAndSetComponents(node, domain, resource); } diff --git a/test/com/isode/stroke/jid/JIDTest.java b/test/com/isode/stroke/jid/JIDTest.java index 96de429..69bee05 100644 --- a/test/com/isode/stroke/jid/JIDTest.java +++ b/test/com/isode/stroke/jid/JIDTest.java @@ -12,12 +12,10 @@ package com.isode.stroke.jid; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; + import org.junit.Test; -import com.isode.stroke.jid.JID; public class JIDTest { @@ -155,6 +153,12 @@ public class JIDTest { assertFalse(testling.isValid()); } + + @Test + public void testConstructorWithStrings_EmptyResource() { + JID testling = new JID("foo","bar",""); + assertFalse(testling.isValid()); + } @Test -- cgit v0.10.2-6-g49f6