Merge pull request #740 from SamWhited/jidrpfix
Fix RFC 6122 implementation
This commit is contained in:
commit
138345c5bf
|
@ -68,17 +68,24 @@ public final class Jid {
|
||||||
if (jid.isEmpty() || jid.length() > 3071) {
|
if (jid.isEmpty() || jid.length() > 3071) {
|
||||||
throw new InvalidJidException(InvalidJidException.INVALID_LENGTH);
|
throw new InvalidJidException(InvalidJidException.INVALID_LENGTH);
|
||||||
}
|
}
|
||||||
if (atCount > 1 || slashCount > 1 ||
|
|
||||||
jid.startsWith("@") || jid.endsWith("@") ||
|
// Go ahead and check if the localpart or resourcepart is empty.
|
||||||
jid.startsWith("/") || jid.endsWith("/")) {
|
if (jid.startsWith("@") || (jid.endsWith("@") && slashCount == 0) || jid.startsWith("/") || (jid.endsWith("/") && slashCount < 2)) {
|
||||||
throw new InvalidJidException(InvalidJidException.INVALID_CHARACTER);
|
throw new InvalidJidException(InvalidJidException.INVALID_CHARACTER);
|
||||||
}
|
}
|
||||||
|
|
||||||
String finaljid;
|
String finaljid;
|
||||||
|
|
||||||
final int domainpartStart;
|
final int domainpartStart;
|
||||||
if (atCount == 1) {
|
|
||||||
final int atLoc = jid.indexOf("@");
|
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);
|
final String lp = jid.substring(0, atLoc);
|
||||||
try {
|
try {
|
||||||
localpart = Stringprep.nodeprep(lp);
|
localpart = Stringprep.nodeprep(lp);
|
||||||
|
@ -90,15 +97,10 @@ public final class Jid {
|
||||||
}
|
}
|
||||||
domainpartStart = atLoc + 1;
|
domainpartStart = atLoc + 1;
|
||||||
finaljid = lp + "@";
|
finaljid = lp + "@";
|
||||||
} else {
|
|
||||||
localpart = "";
|
|
||||||
finaljid = "";
|
|
||||||
domainpartStart = 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
final String dp;
|
final String dp;
|
||||||
if (slashCount == 1) {
|
if (slashCount > 0) {
|
||||||
final int slashLoc = jid.indexOf("/");
|
|
||||||
final String rp = jid.substring(slashLoc + 1, jid.length());
|
final String rp = jid.substring(slashLoc + 1, jid.length());
|
||||||
try {
|
try {
|
||||||
resourcepart = Stringprep.resourceprep(rp);
|
resourcepart = Stringprep.resourceprep(rp);
|
||||||
|
|
Loading…
Reference in New Issue