[Pkg-javascript-commits] [ltx] 52/469: JID: use node-stringprep normalization
Jonas Smedegaard
dr at jones.dk
Wed Aug 31 13:00:59 UTC 2016
This is an automated email from the git hooks/post-receive script.
js pushed a commit to branch master
in repository ltx.
commit 27d6561e29f5a9f91e939a597cc6f358387b5fe2
Author: Astro <astro at spaceboyz.net>
Date: Sat Aug 14 00:19:41 2010 +0200
JID: use node-stringprep normalization
---
lib/xmpp/jid.js | 36 ++++++++++++++++++++++++++++++------
package.json | 4 +++-
test/test_jid.js | 25 ++++++++++++++++++++++++-
3 files changed, 57 insertions(+), 8 deletions(-)
diff --git a/lib/xmpp/jid.js b/lib/xmpp/jid.js
index 296d427..69afe34 100644
--- a/lib/xmpp/jid.js
+++ b/lib/xmpp/jid.js
@@ -1,24 +1,29 @@
+var StringPrep = require('node-stringprep').StringPrep;
+var nameprep = new StringPrep('nameprep');
+var nodeprep = new StringPrep('nodeprep');
+var resourceprep = new StringPrep('resourceprep');
+
function JID(a, b, c) {
if (a && b == null && c == null) {
this.parseJID(a);
} else if (b) {
- this.user = a;
- this.domain = b;
- this.resource = c;
+ this.setUser(a);
+ this.setDomain(b);
+ this.setResource(c);
} else
throw 'Argument error';
}
JID.prototype.parseJID = function(s) {
if (s.indexOf('@') >= 0) {
- this.user = s.substr(0, s.indexOf('@'));
+ this.setUser(s.substr(0, s.indexOf('@')));
s = s.substr(s.indexOf('@') + 1);
}
if (s.indexOf('/') >= 0) {
- this.resource = s.substr(s.indexOf('/') + 1);
+ this.setResource(s.substr(s.indexOf('/') + 1));
s = s.substr(0, s.indexOf('/'));
}
- this.domain = s;
+ this.setDomain(s);
};
JID.prototype.toString = function() {
@@ -30,6 +35,9 @@ JID.prototype.toString = function() {
return s;
};
+/**
+ * Convenience method to distinguish users
+ **/
JID.prototype.bare = function() {
if (this.resource)
return new JID(this.user, this.domain, null);
@@ -37,10 +45,26 @@ JID.prototype.bare = function() {
return this;
};
+/**
+ * Comparison function
+ **/
JID.prototype.equals = function(other) {
return this.user == other.user &&
this.domain == other.domain &&
this.resource == other.resource;
};
+/**
+ * Setters that do stringprep normalization.
+ **/
+JID.prototype.setUser = function(user) {
+ this.user = user && nodeprep.prepare(user);
+};
+JID.prototype.setDomain = function(domain) {
+ this.domain = domain && nameprep.prepare(domain);
+};
+JID.prototype.setResource = function(resource) {
+ this.resource = resource && resourceprep.prepare(resource);
+};
+
exports.JID = JID;
diff --git a/package.json b/package.json
index 6de73bb..da3f1f5 100644
--- a/package.json
+++ b/package.json
@@ -3,7 +3,9 @@
,"main": "./lib/xmpp"
,"description": "Idiomatic XMPP client & component library for node.js"
,"author": "Stephan Maka"
-,"dependencies": {"node-expat": "1.1.0"}
+,"dependencies": [{"node-expat": "1.1.0"
+ ,"node-stringprep": "0.0.1"
+ }],
,"repositories": [{ "type": "git"
,"path": "git://github.com/astro/node-xmpp.git"
}]
diff --git a/test/test_jid.js b/test/test_jid.js
index 3e26470..c005081 100644
--- a/test/test_jid.js
+++ b/test/test_jid.js
@@ -71,8 +71,31 @@ vows.describe('JID').addBatch({
var j1 = new xmpp.JID('foo at bar/baz');
var j2 = new xmpp.JID('quux at bar/baz');
assert.equal(j1.equals(j2), false);
+ },
+ 'should ignore case in user':
+ function() {
+ var j1 = new xmpp.JID('foo at bar/baz');
+ var j2 = new xmpp.JID('FOO at bar/baz');
+ assert.equal(j1.equals(j2), true);
+ },
+ 'should ignore case in domain':
+ function() {
+ var j1 = new xmpp.JID('foo at bar/baz');
+ var j2 = new xmpp.JID('foo at BAR/baz');
+ assert.equal(j1.equals(j2), true);
+ },
+ 'should not ignore case in resource':
+ function() {
+ var j1 = new xmpp.JID('foo at bar/baz');
+ var j2 = new xmpp.JID('foo at bar/Baz');
+ assert.equal(j1.equals(j2), false);
+ },
+ 'should ignore international caseness':
+ function() {
+ var j1 = new xmpp.JID('föö@bär/baß');
+ var j2 = new xmpp.JID('fÖö@BÄR/baß');
+ assert.equal(j1.equals(j2), true);
}
-
}
}).run();
--
Alioth's /usr/local/bin/git-commit-notice on /srv/git.debian.org/git/pkg-javascript/ltx.git
More information about the Pkg-javascript-commits
mailing list