changeset 15:60c80751cfa5

JID handling conforming to the RFC.
author Emmanuel Gil Peyrot <linkmauve@linkmauve.fr>
date Tue, 19 Oct 2010 17:48:45 +0200
parents 06abc804e2ab
children 95fc43d1bd54
files util.js
diffstat 1 files changed, 10 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/util.js
+++ b/util.js
@@ -25,21 +25,23 @@ util.makeRandomId = function() {
 };
 
 var JID = function(jid) {
-	var a = jid.indexOf('@');
-	var b = jid.indexOf('/', a);
 	this.full = jid;
-	if (b == -1) {
+
+	var s = jid.indexOf('/');
+	if (s == -1)
 		this.resource = '';
-	} else {
-		this.resource = jid.substring(b+1);
-		jid = jid.substring(0, b);
+	else {
+		this.resource = jid.substring(s+1);
+		jid = jid.substr(0, s);
 	}
+
+	var a = jid.indexOf('@');
 	if (a == -1) {
 		this.user = '';
 		this.server = jid;
 	} else {
-		this.user = jid.substring(0, a);
-		this.server = jid.substring(a+1);
+		this.user = jid.substr(0, a);
+		this.server = jid.substr(a+1);
 	}
 	this.bare = jid;
 };