Merge pull request #740 from SamWhited/jidrpfix

Fix RFC 6122 implementation
This commit is contained in:
Daniel Gultsch 2014-12-03 00:12:36 +01:00
commit 138345c5bf

View File

@ -68,17 +68,24 @@ public final class Jid {
if (jid.isEmpty() || jid.length() > 3071) {
throw new InvalidJidException(InvalidJidException.INVALID_LENGTH);
}
if (atCount > 1 || slashCount > 1 ||
jid.startsWith("@") || jid.endsWith("@") ||
jid.startsWith("/") || jid.endsWith("/")) {
// Go ahead and check if the localpart or resourcepart is empty.
if (jid.startsWith("@") || (jid.endsWith("@") && slashCount == 0) || jid.startsWith("/") || (jid.endsWith("/") && slashCount < 2)) {
throw new InvalidJidException(InvalidJidException.INVALID_CHARACTER);
}
String finaljid;
final int domainpartStart;
if (atCount == 1) {
final int atLoc = jid.indexOf("@");
final int slashLoc = jid.indexOf("/");
// If there is no "@" in the JID (eg. "example.net" or "example.net/resource")
// or there are one or more "@" signs but they're all in the resourcepart (eg. "example.net/@/rp@"):
if (atCount == 0 || (atCount > 0 && slashLoc != -1 && atLoc > slashLoc)) {
localpart = "";
finaljid = "";
domainpartStart = 0;
} else {
final String lp = jid.substring(0, atLoc);
try {
localpart = Stringprep.nodeprep(lp);
@ -90,15 +97,10 @@ public final class Jid {
}
domainpartStart = atLoc + 1;
finaljid = lp + "@";
} else {
localpart = "";
finaljid = "";
domainpartStart = 0;
}
final String dp;
if (slashCount == 1) {
final int slashLoc = jid.indexOf("/");
if (slashCount > 0) {
final String rp = jid.substring(slashLoc + 1, jid.length());
try {
resourcepart = Stringprep.resourceprep(rp);