Comparing version 0.11.0 to 0.12.0
32
index.js
@@ -1,25 +0,25 @@ | ||
'use strict' | ||
"use strict"; | ||
const JID = require('./lib/JID') | ||
const escaping = require('./lib/escaping') | ||
const parse = require('./lib/parse') | ||
const JID = require("./lib/JID"); | ||
const escaping = require("./lib/escaping"); | ||
const parse = require("./lib/parse"); | ||
function jid(...args) { | ||
if (!args[1] && !args[2]) { | ||
return parse(...args) | ||
return parse(...args); | ||
} | ||
return new JID(...args) | ||
return new JID(...args); | ||
} | ||
exports = module.exports = jid.bind() | ||
exports.jid = jid | ||
exports.JID = JID | ||
exports.equal = function(a, b) { | ||
return a.equals(b) | ||
} | ||
module.exports = jid.bind(); | ||
module.exports.jid = jid; | ||
module.exports.JID = JID; | ||
module.exports.equal = function equal(a, b) { | ||
return a.equals(b); | ||
}; | ||
exports.detectEscape = escaping.detect | ||
exports.escapeLocal = escaping.escape | ||
exports.unescapeLocal = escaping.unescape | ||
exports.parse = parse | ||
module.exports.detectEscape = escaping.detect; | ||
module.exports.escapeLocal = escaping.escape; | ||
module.exports.unescapeLocal = escaping.unescape; | ||
module.exports.parse = parse; |
@@ -1,6 +0,6 @@ | ||
'use strict' | ||
"use strict"; | ||
module.exports.detect = function(local) { | ||
module.exports.detect = function detect(local) { | ||
if (!local) { | ||
return false | ||
return false; | ||
} | ||
@@ -10,22 +10,21 @@ | ||
const tmp = local | ||
.replace(/\\20/g, '') | ||
.replace(/\\22/g, '') | ||
.replace(/\\26/g, '') | ||
.replace(/\\27/g, '') | ||
.replace(/\\2f/g, '') | ||
.replace(/\\3a/g, '') | ||
.replace(/\\3c/g, '') | ||
.replace(/\\3e/g, '') | ||
.replace(/\\40/g, '') | ||
.replace(/\\5c/g, '') | ||
.replace(/\\20/g, "") | ||
.replace(/\\22/g, "") | ||
.replace(/\\26/g, "") | ||
.replace(/\\27/g, "") | ||
.replace(/\\2f/g, "") | ||
.replace(/\\3a/g, "") | ||
.replace(/\\3c/g, "") | ||
.replace(/\\3e/g, "") | ||
.replace(/\\40/g, "") | ||
.replace(/\\5c/g, ""); | ||
// Detect if we have unescaped sequences | ||
// eslint-disable-next-line unicorn/regex-shorthand | ||
const search = tmp.search(/\\| |"|&|'|\/|:|<|>|@/g) | ||
const search = tmp.search(/[ "&'/:<>@\\]/g); | ||
if (search === -1) { | ||
return false | ||
return false; | ||
} | ||
return true | ||
} | ||
return true; | ||
}; | ||
@@ -39,21 +38,21 @@ /** | ||
*/ | ||
module.exports.escape = function(local) { | ||
module.exports.escape = function escape(local) { | ||
if (local === null) { | ||
return null | ||
return null; | ||
} | ||
return local | ||
.replace(/^\s+|\s+$/g, '') | ||
.replace(/\\/g, '\\5c') | ||
.replace(/ /g, '\\20') | ||
.replace(/"/g, '\\22') | ||
.replace(/&/g, '\\26') | ||
.replace(/'/g, '\\27') | ||
.replace(/\//g, '\\2f') | ||
.replace(/:/g, '\\3a') | ||
.replace(/</g, '\\3c') | ||
.replace(/>/g, '\\3e') | ||
.replace(/@/g, '\\40') | ||
.replace(/\3a/g, '\u0005c3a') | ||
} | ||
.replace(/^\s+|\s+$/g, "") | ||
.replace(/\\/g, "\\5c") | ||
.replace(/ /g, "\\20") | ||
.replace(/"/g, "\\22") | ||
.replace(/&/g, "\\26") | ||
.replace(/'/g, "\\27") | ||
.replace(/\//g, "\\2f") | ||
.replace(/:/g, "\\3a") | ||
.replace(/</g, "\\3c") | ||
.replace(/>/g, "\\3e") | ||
.replace(/@/g, "\\40") | ||
.replace(/\3a/g, "\u0005c3a"); | ||
}; | ||
@@ -67,18 +66,18 @@ /** | ||
*/ | ||
module.exports.unescape = function(local) { | ||
module.exports.unescape = function unescape(local) { | ||
if (local === null) { | ||
return null | ||
return null; | ||
} | ||
return local | ||
.replace(/\\20/g, ' ') | ||
.replace(/\\20/g, " ") | ||
.replace(/\\22/g, '"') | ||
.replace(/\\26/g, '&') | ||
.replace(/\\26/g, "&") | ||
.replace(/\\27/g, "'") | ||
.replace(/\\2f/g, '/') | ||
.replace(/\\3a/g, ':') | ||
.replace(/\\3c/g, '<') | ||
.replace(/\\3e/g, '>') | ||
.replace(/\\40/g, '@') | ||
.replace(/\\5c/g, '\\') | ||
} | ||
.replace(/\\2f/g, "/") | ||
.replace(/\\3a/g, ":") | ||
.replace(/\\3c/g, "<") | ||
.replace(/\\3e/g, ">") | ||
.replace(/\\40/g, "@") | ||
.replace(/\\5c/g, "\\"); | ||
}; |
@@ -1,4 +0,4 @@ | ||
'use strict' | ||
"use strict"; | ||
const escaping = require('./escaping') | ||
const escaping = require("./escaping"); | ||
@@ -15,30 +15,30 @@ /** | ||
constructor(local, domain, resource) { | ||
if (typeof domain !== 'string' || !domain) { | ||
throw new TypeError(`Invalid domain.`) | ||
if (typeof domain !== "string" || !domain) { | ||
throw new TypeError(`Invalid domain.`); | ||
} | ||
this.setDomain(domain) | ||
this.setLocal(typeof local === 'string' ? local : '') | ||
this.setResource(typeof resource === 'string' ? resource : '') | ||
this.setDomain(domain); | ||
this.setLocal(typeof local === "string" ? local : ""); | ||
this.setResource(typeof resource === "string" ? resource : ""); | ||
} | ||
[Symbol.toPrimitive](hint) { | ||
if (hint === 'number') { | ||
return NaN | ||
if (hint === "number") { | ||
return NaN; | ||
} | ||
return this.toString() | ||
return this.toString(); | ||
} | ||
toString(unescape) { | ||
let s = this._domain | ||
let s = this._domain; | ||
if (this._local) { | ||
s = this.getLocal(unescape) + '@' + s | ||
s = this.getLocal(unescape) + "@" + s; | ||
} | ||
if (this._resource) { | ||
s = s + '/' + this._resource | ||
s = s + "/" + this._resource; | ||
} | ||
return s | ||
return s; | ||
} | ||
@@ -51,6 +51,6 @@ | ||
if (this._resource) { | ||
return new JID(this._local, this._domain, null) | ||
return new JID(this._local, this._domain, null); | ||
} | ||
return this | ||
return this; | ||
} | ||
@@ -66,3 +66,3 @@ | ||
this._resource === other._resource | ||
) | ||
); | ||
} | ||
@@ -74,23 +74,19 @@ | ||
setLocal(local, escape) { | ||
escape = escape || escaping.detect(local) | ||
escape = escape || escaping.detect(local); | ||
if (escape) { | ||
local = escaping.escape(local) | ||
local = escaping.escape(local); | ||
} | ||
this._local = local && local.toLowerCase() | ||
return this | ||
this._local = local && local.toLowerCase(); | ||
return this; | ||
} | ||
getLocal(unescape) { | ||
unescape = unescape || false | ||
let local = null | ||
unescape = unescape || false; | ||
let local = null; | ||
if (unescape) { | ||
local = escaping.unescape(this._local) | ||
} else { | ||
local = this._local | ||
} | ||
local = unescape ? escaping.unescape(this._local) : this._local; | ||
return local | ||
return local; | ||
} | ||
@@ -102,8 +98,8 @@ | ||
setDomain(domain) { | ||
this._domain = domain.toLowerCase() | ||
return this | ||
this._domain = domain.toLowerCase(); | ||
return this; | ||
} | ||
getDomain() { | ||
return this._domain | ||
return this._domain; | ||
} | ||
@@ -115,26 +111,26 @@ | ||
setResource(resource) { | ||
this._resource = resource | ||
return this | ||
this._resource = resource; | ||
return this; | ||
} | ||
getResource() { | ||
return this._resource | ||
return this._resource; | ||
} | ||
} | ||
Object.defineProperty(JID.prototype, 'local', { | ||
Object.defineProperty(JID.prototype, "local", { | ||
get: JID.prototype.getLocal, | ||
set: JID.prototype.setLocal, | ||
}) | ||
}); | ||
Object.defineProperty(JID.prototype, 'domain', { | ||
Object.defineProperty(JID.prototype, "domain", { | ||
get: JID.prototype.getDomain, | ||
set: JID.prototype.setDomain, | ||
}) | ||
}); | ||
Object.defineProperty(JID.prototype, 'resource', { | ||
Object.defineProperty(JID.prototype, "resource", { | ||
get: JID.prototype.getResource, | ||
set: JID.prototype.setResource, | ||
}) | ||
}); | ||
module.exports = JID | ||
module.exports = JID; |
@@ -1,22 +0,22 @@ | ||
'use strict' | ||
"use strict"; | ||
const JID = require('../lib/JID') | ||
const JID = require("../lib/JID"); | ||
module.exports = function parse(s) { | ||
let local | ||
let resource | ||
let local; | ||
let resource; | ||
const resourceStart = s.indexOf('/') | ||
const resourceStart = s.indexOf("/"); | ||
if (resourceStart !== -1) { | ||
resource = s.slice(resourceStart + 1) | ||
s = s.slice(0, resourceStart) | ||
resource = s.slice(resourceStart + 1); | ||
s = s.slice(0, resourceStart); | ||
} | ||
const atStart = s.indexOf('@') | ||
const atStart = s.indexOf("@"); | ||
if (atStart !== -1) { | ||
local = s.slice(0, atStart) | ||
s = s.slice(atStart + 1) | ||
local = s.slice(0, atStart); | ||
s = s.slice(atStart + 1); | ||
} | ||
return new JID(local, s, resource) | ||
} | ||
return new JID(local, s, resource); | ||
}; |
@@ -7,3 +7,3 @@ { | ||
"bugs": "http://github.com/xmppjs/xmpp.js/issues", | ||
"version": "0.11.0", | ||
"version": "0.12.0", | ||
"license": "ISC", | ||
@@ -15,3 +15,3 @@ "keywords": [ | ||
"engines": { | ||
"node": ">= 10.0.0", | ||
"node": ">= 12.4.0", | ||
"yarn": ">= 1.0.0" | ||
@@ -22,3 +22,3 @@ }, | ||
}, | ||
"gitHead": "c0548a598826ae55cf195f296058b344064af7fd" | ||
"gitHead": "75f7bdf7805dced03f616b66dc16e2a067b46480" | ||
} |
@@ -20,3 +20,3 @@ # JID | ||
```js | ||
var jid = require('@xmpp/jid') | ||
var jid = require("@xmpp/jid"); | ||
@@ -26,9 +26,9 @@ /* | ||
*/ | ||
var addr = jid('alice@wonderland.net/rabbithole') | ||
var addr = jid('alice', 'wonderland.net', 'rabbithole') | ||
var addr = jid("alice@wonderland.net/rabbithole"); | ||
var addr = jid("alice", "wonderland.net", "rabbithole"); | ||
addr instanceof jid.JID // true | ||
addr instanceof jid.JID; // true | ||
// domain JIDs are created passing the domain as the first argument | ||
var addr = jid('wonderland.net') | ||
var addr = jid("wonderland.net"); | ||
@@ -38,7 +38,7 @@ /* | ||
*/ | ||
addr.local = 'alice' | ||
addr.local // alice | ||
addr.local = "alice"; | ||
addr.local; // alice | ||
// same as | ||
addr.setLocal('alice') | ||
addr.getLocal() // alice | ||
addr.setLocal("alice"); | ||
addr.getLocal(); // alice | ||
@@ -48,7 +48,7 @@ /* | ||
*/ | ||
addr.domain = 'wonderland.net' | ||
addr.domain // wonderland.net | ||
addr.domain = "wonderland.net"; | ||
addr.domain; // wonderland.net | ||
// same as | ||
addr.setDomain('wonderland.net') | ||
addr.getDomain() // wonderland.net | ||
addr.setDomain("wonderland.net"); | ||
addr.getDomain(); // wonderland.net | ||
@@ -58,14 +58,14 @@ /* | ||
*/ | ||
addr.resource = 'rabbithole' | ||
addr.resource // rabbithole | ||
addr.resource = "rabbithole"; | ||
addr.resource; // rabbithole | ||
// same as | ||
addr.setResource('rabbithole') | ||
addr.getResource() // rabbithole | ||
addr.setResource("rabbithole"); | ||
addr.getResource(); // rabbithole | ||
addr.toString() // alice@wonderland.net/rabbithole | ||
addr.bare() // returns a JID without resource | ||
addr.toString(); // alice@wonderland.net/rabbithole | ||
addr.bare(); // returns a JID without resource | ||
addr.equals(some_jid) // returns true if the two JIDs are equal, false otherwise | ||
addr.equals(some_jid); // returns true if the two JIDs are equal, false otherwise | ||
// same as | ||
jid.equal(addr, some_jid) | ||
jid.equal(addr, some_jid); | ||
``` | ||
@@ -78,6 +78,6 @@ | ||
```js | ||
const addr = jid('contact@example.net', 'xmpp.net') | ||
addr.toString() // contact\40example.net@xmpp.net | ||
const addr = jid("contact@example.net", "xmpp.net"); | ||
addr.toString(); // contact\40example.net@xmpp.net | ||
// for display purpose only | ||
addr.toString(true) // contact@example.net@xmpp.net | ||
addr.toString(true); // contact@example.net@xmpp.net | ||
``` | ||
@@ -88,5 +88,5 @@ | ||
```js | ||
jid('contact@example.net', 'xmpp.net') | ||
jid("contact@example.net", "xmpp.net"); | ||
// over | ||
jid('contact@example.net@xmpp.net') | ||
jid("contact@example.net@xmpp.net"); | ||
``` | ||
@@ -93,0 +93,0 @@ |
@@ -1,46 +0,46 @@ | ||
'use strict' | ||
"use strict"; | ||
const test = require('ava') | ||
const jid = require('..') | ||
const test = require("ava"); | ||
const jid = require(".."); | ||
test('should parsed JIDs should be equal', t => { | ||
const j1 = jid('foo@bar/baz') | ||
const j2 = jid('foo@bar/baz') | ||
t.is(j1.equals(j2), true) | ||
}) | ||
test("should parsed JIDs should be equal", (t) => { | ||
const j1 = jid("foo@bar/baz"); | ||
const j2 = jid("foo@bar/baz"); | ||
t.is(j1.equals(j2), true); | ||
}); | ||
test('should parsed JIDs should be not equal', t => { | ||
const j1 = jid('foo@bar/baz') | ||
const j2 = jid('quux@bar/baz') | ||
t.is(j1.equals(j2), false) | ||
}) | ||
test("should parsed JIDs should be not equal", (t) => { | ||
const j1 = jid("foo@bar/baz"); | ||
const j2 = jid("quux@bar/baz"); | ||
t.is(j1.equals(j2), false); | ||
}); | ||
test('should ignore case in user', t => { | ||
const j1 = jid('foo@bar/baz') | ||
const j2 = jid('FOO@bar/baz') | ||
t.is(j1.equals(j2), true) | ||
}) | ||
test("should ignore case in user", (t) => { | ||
const j1 = jid("foo@bar/baz"); | ||
const j2 = jid("FOO@bar/baz"); | ||
t.is(j1.equals(j2), true); | ||
}); | ||
test('should ignore case in domain', t => { | ||
const j1 = jid('foo@bar/baz') | ||
const j2 = jid('foo@BAR/baz') | ||
t.is(j1.equals(j2), true) | ||
}) | ||
test("should ignore case in domain", (t) => { | ||
const j1 = jid("foo@bar/baz"); | ||
const j2 = jid("foo@BAR/baz"); | ||
t.is(j1.equals(j2), true); | ||
}); | ||
test('should not ignore case in resource', t => { | ||
const j1 = jid('foo@bar/baz') | ||
const j2 = jid('foo@bar/Baz') | ||
t.is(j1.equals(j2), false) | ||
}) | ||
test("should not ignore case in resource", (t) => { | ||
const j1 = jid("foo@bar/baz"); | ||
const j2 = jid("foo@bar/Baz"); | ||
t.is(j1.equals(j2), false); | ||
}); | ||
test('should ignore international caseness', t => { | ||
const j1 = jid('föö@bär/baß') | ||
const j2 = jid('fÖö@BÄR/baß') | ||
t.is(j1.equals(j2), true) | ||
}) | ||
test("should ignore international caseness", (t) => { | ||
const j1 = jid("föö@bär/baß"); | ||
const j2 = jid("fÖö@BÄR/baß"); | ||
t.is(j1.equals(j2), true); | ||
}); | ||
test('should work with bare JIDs', t => { | ||
const j1 = jid('romeo@example.net/9519407536580081') | ||
const j2 = jid('romeo@example.net') | ||
t.is(j1.bare().equals(j2), true) | ||
}) | ||
test("should work with bare JIDs", (t) => { | ||
const j1 = jid("romeo@example.net/9519407536580081"); | ||
const j2 = jid("romeo@example.net"); | ||
t.is(j1.bare().equals(j2), true); | ||
}); |
@@ -1,18 +0,18 @@ | ||
'use strict' | ||
"use strict"; | ||
const test = require('ava') | ||
const jid = require('..') | ||
const test = require("ava"); | ||
const jid = require(".."); | ||
test('Should not change string - issue 43', t => { | ||
const test = 'test\u001A@example.com' | ||
test("Should not change string - issue 43", (t) => { | ||
const test = "test\u001A@example.com"; | ||
const addr = jid(test) | ||
t.is(addr.local, 'test\u001A') | ||
}) | ||
const addr = jid(test); | ||
t.is(addr.local, "test\u001A"); | ||
}); | ||
test('Should escape - issue 43', t => { | ||
const test = 'test\u001Aa@example.com' | ||
test("Should escape - issue 43", (t) => { | ||
const test = "test\u001Aa@example.com"; | ||
const addr = jid(test) | ||
t.is(addr.local, 'testa') | ||
}) | ||
const addr = jid(test); | ||
t.is(addr.local, "testa"); | ||
}); |
@@ -1,136 +0,136 @@ | ||
'use strict' | ||
"use strict"; | ||
const test = require('ava') | ||
const JID = require('../lib/JID') | ||
const test = require("ava"); | ||
const JID = require("../lib/JID"); | ||
test('escape `space cadet@example.com`', t => { | ||
const esc = new JID('space cadet', 'example.com') | ||
t.is(esc.toString(), 'space\\20cadet@example.com') | ||
t.is(esc.toString(true), 'space cadet@example.com') | ||
}) | ||
test("escape `space cadet@example.com`", (t) => { | ||
const esc = new JID("space cadet", "example.com"); | ||
t.is(esc.toString(), "space\\20cadet@example.com"); | ||
t.is(esc.toString(true), "space cadet@example.com"); | ||
}); | ||
test('escape `call me "ishmael"@example.com`', t => { | ||
const esc = new JID('call me "ishmael"', 'example.com') | ||
t.is(esc.toString(), 'call\\20me\\20\\22ishmael\\22@example.com') | ||
t.is(esc.toString(true), 'call me "ishmael"@example.com') | ||
}) | ||
test('escape `call me "ishmael"@example.com`', (t) => { | ||
const esc = new JID('call me "ishmael"', "example.com"); | ||
t.is(esc.toString(), "call\\20me\\20\\22ishmael\\22@example.com"); | ||
t.is(esc.toString(true), 'call me "ishmael"@example.com'); | ||
}); | ||
test('escape `at&t guy@example.com`', t => { | ||
const esc = new JID('at&t guy', 'example.com') | ||
t.is(esc.toString(), 'at\\26t\\20guy@example.com') | ||
t.is(esc.toString(true), 'at&t guy@example.com') | ||
}) | ||
test("escape `at&t guy@example.com`", (t) => { | ||
const esc = new JID("at&t guy", "example.com"); | ||
t.is(esc.toString(), "at\\26t\\20guy@example.com"); | ||
t.is(esc.toString(true), "at&t guy@example.com"); | ||
}); | ||
test("escape `d'artagnan@example.com`", t => { | ||
const esc = new JID("d'artagnan", 'example.com') | ||
t.is(esc.toString(), 'd\\27artagnan@example.com') | ||
t.is(esc.toString(true), "d'artagnan@example.com") | ||
}) | ||
test("escape `d'artagnan@example.com`", (t) => { | ||
const esc = new JID("d'artagnan", "example.com"); | ||
t.is(esc.toString(), "d\\27artagnan@example.com"); | ||
t.is(esc.toString(true), "d'artagnan@example.com"); | ||
}); | ||
test('escape `/.fanboy@example.com`', t => { | ||
const esc = new JID('/.fanboy', 'example.com') | ||
t.is(esc.toString(), '\\2f.fanboy@example.com') | ||
t.is(esc.toString(true), '/.fanboy@example.com') | ||
}) | ||
test("escape `/.fanboy@example.com`", (t) => { | ||
const esc = new JID("/.fanboy", "example.com"); | ||
t.is(esc.toString(), "\\2f.fanboy@example.com"); | ||
t.is(esc.toString(true), "/.fanboy@example.com"); | ||
}); | ||
test('escape `::foo::@example.com`', t => { | ||
const esc = new JID('::foo::', 'example.com') | ||
t.is(esc.toString(), '\\3a\\3afoo\\3a\\3a@example.com') | ||
t.is(esc.toString(true), '::foo::@example.com') | ||
}) | ||
test("escape `::foo::@example.com`", (t) => { | ||
const esc = new JID("::foo::", "example.com"); | ||
t.is(esc.toString(), "\\3a\\3afoo\\3a\\3a@example.com"); | ||
t.is(esc.toString(true), "::foo::@example.com"); | ||
}); | ||
test('escape `<foo>@example.com`', t => { | ||
const esc = new JID('<foo>', 'example.com') | ||
t.is(esc.toString(), '\\3cfoo\\3e@example.com') | ||
t.is(esc.toString(true), '<foo>@example.com') | ||
}) | ||
test("escape `<foo>@example.com`", (t) => { | ||
const esc = new JID("<foo>", "example.com"); | ||
t.is(esc.toString(), "\\3cfoo\\3e@example.com"); | ||
t.is(esc.toString(true), "<foo>@example.com"); | ||
}); | ||
test('escape `user@host@example.com`', t => { | ||
const esc = new JID('user@host', 'example.com') | ||
t.is(esc.toString(), 'user\\40host@example.com') | ||
t.is(esc.toString(true), 'user@host@example.com') | ||
}) | ||
test("escape `user@host@example.com`", (t) => { | ||
const esc = new JID("user@host", "example.com"); | ||
t.is(esc.toString(), "user\\40host@example.com"); | ||
t.is(esc.toString(true), "user@host@example.com"); | ||
}); | ||
test('escape `c:\\net@example.com`', t => { | ||
const esc = new JID('c:\\net', 'example.com') | ||
t.is(esc.toString(), 'c\\3a\\5cnet@example.com') | ||
t.is(esc.toString(true), 'c:\\net@example.com') | ||
}) | ||
test("escape `c:\\net@example.com`", (t) => { | ||
const esc = new JID("c:\\net", "example.com"); | ||
t.is(esc.toString(), "c\\3a\\5cnet@example.com"); | ||
t.is(esc.toString(true), "c:\\net@example.com"); | ||
}); | ||
test('escape `c:\\\\net@example.com`', t => { | ||
const esc = new JID('c:\\\\net', 'example.com') | ||
t.is(esc.toString(), 'c\\3a\\5c\\5cnet@example.com') | ||
t.is(esc.toString(true), 'c:\\\\net@example.com') | ||
}) | ||
test("escape `c:\\\\net@example.com`", (t) => { | ||
const esc = new JID("c:\\\\net", "example.com"); | ||
t.is(esc.toString(), "c\\3a\\5c\\5cnet@example.com"); | ||
t.is(esc.toString(true), "c:\\\\net@example.com"); | ||
}); | ||
test('escape `c:\\cool stuff@example.com`', t => { | ||
const esc = new JID('c:\\cool stuff', 'example.com') | ||
t.is(esc.toString(), 'c\\3a\\5ccool\\20stuff@example.com') | ||
t.is(esc.toString(true), 'c:\\cool stuff@example.com') | ||
}) | ||
test("escape `c:\\cool stuff@example.com`", (t) => { | ||
const esc = new JID("c:\\cool stuff", "example.com"); | ||
t.is(esc.toString(), "c\\3a\\5ccool\\20stuff@example.com"); | ||
t.is(esc.toString(true), "c:\\cool stuff@example.com"); | ||
}); | ||
test('escape `c:\\5commas@example.com`', t => { | ||
const esc = new JID('c:\\5commas', 'example.com') | ||
t.is(esc.toString(), 'c\\3a\\5c5commas@example.com') | ||
t.is(esc.toString(true), 'c:\\5commas@example.com') | ||
}) | ||
test("escape `c:\\5commas@example.com`", (t) => { | ||
const esc = new JID("c:\\5commas", "example.com"); | ||
t.is(esc.toString(), "c\\3a\\5c5commas@example.com"); | ||
t.is(esc.toString(true), "c:\\5commas@example.com"); | ||
}); | ||
test('escape `space\\20cadet@example.com`', t => { | ||
const esc = new JID('space\\20cadet', 'example.com') | ||
t.is(esc.toString(), 'space\\20cadet@example.com') | ||
t.is(esc.toString(true), 'space cadet@example.com') | ||
}) | ||
test("escape `space\\20cadet@example.com`", (t) => { | ||
const esc = new JID("space\\20cadet", "example.com"); | ||
t.is(esc.toString(), "space\\20cadet@example.com"); | ||
t.is(esc.toString(true), "space cadet@example.com"); | ||
}); | ||
test('escape `at\\26t\\20guy@example.com`', t => { | ||
const esc = new JID('at\\26t\\20guy', 'example.com') | ||
t.is(esc.toString(), 'at\\26t\\20guy@example.com') | ||
t.is(esc.toString(true), 'at&t guy@example.com') | ||
}) | ||
test("escape `at\\26t\\20guy@example.com`", (t) => { | ||
const esc = new JID("at\\26t\\20guy", "example.com"); | ||
t.is(esc.toString(), "at\\26t\\20guy@example.com"); | ||
t.is(esc.toString(true), "at&t guy@example.com"); | ||
}); | ||
test('escape `d\\27artagnan@example.com`', t => { | ||
const esc = new JID('d\\27artagnan', 'example.com') | ||
t.is(esc.toString(), 'd\\27artagnan@example.com') | ||
t.is(esc.toString(true), "d'artagnan@example.com") | ||
}) | ||
test("escape `d\\27artagnan@example.com`", (t) => { | ||
const esc = new JID("d\\27artagnan", "example.com"); | ||
t.is(esc.toString(), "d\\27artagnan@example.com"); | ||
t.is(esc.toString(true), "d'artagnan@example.com"); | ||
}); | ||
test('escape `\\2f.fanboy@example.com`', t => { | ||
const esc = new JID('\\2f.fanboy', 'example.com') | ||
t.is(esc.toString(), '\\2f.fanboy@example.com') | ||
t.is(esc.toString(true), '/.fanboy@example.com') | ||
}) | ||
test("escape `\\2f.fanboy@example.com`", (t) => { | ||
const esc = new JID("\\2f.fanboy", "example.com"); | ||
t.is(esc.toString(), "\\2f.fanboy@example.com"); | ||
t.is(esc.toString(true), "/.fanboy@example.com"); | ||
}); | ||
test('escape `\\3a\\3afoo\\3a\\3a@example.com`', t => { | ||
const esc = new JID('\\3a\\3afoo\\3a\\3a', 'example.com') | ||
t.is(esc.toString(), '\\3a\\3afoo\\3a\\3a@example.com') | ||
t.is(esc.toString(true), '::foo::@example.com') | ||
}) | ||
test("escape `\\3a\\3afoo\\3a\\3a@example.com`", (t) => { | ||
const esc = new JID("\\3a\\3afoo\\3a\\3a", "example.com"); | ||
t.is(esc.toString(), "\\3a\\3afoo\\3a\\3a@example.com"); | ||
t.is(esc.toString(true), "::foo::@example.com"); | ||
}); | ||
test('escape `\\3cfoo\\3e@example.com`', t => { | ||
const esc = new JID('\\3cfoo\\3e', 'example.com') | ||
t.is(esc.toString(), '\\3cfoo\\3e@example.com') | ||
t.is(esc.toString(true), '<foo>@example.com') | ||
}) | ||
test("escape `\\3cfoo\\3e@example.com`", (t) => { | ||
const esc = new JID("\\3cfoo\\3e", "example.com"); | ||
t.is(esc.toString(), "\\3cfoo\\3e@example.com"); | ||
t.is(esc.toString(true), "<foo>@example.com"); | ||
}); | ||
test('escape `user\\40host@example.com`', t => { | ||
const esc = new JID('user\\40host', 'example.com') | ||
t.is(esc.toString(), 'user\\40host@example.com') | ||
t.is(esc.toString(true), 'user@host@example.com') | ||
}) | ||
test("escape `user\\40host@example.com`", (t) => { | ||
const esc = new JID("user\\40host", "example.com"); | ||
t.is(esc.toString(), "user\\40host@example.com"); | ||
t.is(esc.toString(true), "user@host@example.com"); | ||
}); | ||
test('escape `c\\3a\\5cnet@example.com`', t => { | ||
const esc = new JID('c\\3a\\5cnet', 'example.com') | ||
t.is(esc.toString(), 'c\\3a\\5cnet@example.com') | ||
t.is(esc.toString(true), 'c:\\net@example.com') | ||
}) | ||
test("escape `c\\3a\\5cnet@example.com`", (t) => { | ||
const esc = new JID("c\\3a\\5cnet", "example.com"); | ||
t.is(esc.toString(), "c\\3a\\5cnet@example.com"); | ||
t.is(esc.toString(true), "c:\\net@example.com"); | ||
}); | ||
test('escape `c\\3a\\5ccool\\20stuff@example.com`', t => { | ||
const esc = new JID('c\\3a\\5ccool\\20stuff', 'example.com') | ||
t.is(esc.toString(), 'c\\3a\\5ccool\\20stuff@example.com') | ||
t.is(esc.toString(true), 'c:\\cool stuff@example.com') | ||
}) | ||
test("escape `c\\3a\\5ccool\\20stuff@example.com`", (t) => { | ||
const esc = new JID("c\\3a\\5ccool\\20stuff", "example.com"); | ||
t.is(esc.toString(), "c\\3a\\5ccool\\20stuff@example.com"); | ||
t.is(esc.toString(true), "c:\\cool stuff@example.com"); | ||
}); | ||
test('escape `c\\3a\\5c5commas@example.com`', t => { | ||
const esc = new JID('c\\3a\\5c5commas', 'example.com') | ||
t.is(esc.toString(), 'c\\3a\\5c5commas@example.com') | ||
t.is(esc.toString(true), 'c:\\5commas@example.com') | ||
}) | ||
test("escape `c\\3a\\5c5commas@example.com`", (t) => { | ||
const esc = new JID("c\\3a\\5c5commas", "example.com"); | ||
t.is(esc.toString(), "c\\3a\\5c5commas@example.com"); | ||
t.is(esc.toString(true), "c:\\5commas@example.com"); | ||
}); |
@@ -1,37 +0,37 @@ | ||
'use strict' | ||
"use strict"; | ||
const test = require('ava') | ||
const {spy} = require('sinon') | ||
const jid = require('..') | ||
const JID = require('../lib/JID') | ||
const test = require("ava"); | ||
const { spy } = require("sinon"); | ||
const jid = require(".."); | ||
const JID = require("../lib/JID"); | ||
test('equal calls equals on the first argument with the second argument', t => { | ||
const A = jid('foo') | ||
const B = jid('bar') | ||
spy(A, 'equals') | ||
jid.equal(A, B) | ||
t.true(A.equals.calledWith(B)) | ||
A.equals.restore() | ||
}) | ||
test("equal calls equals on the first argument with the second argument", (t) => { | ||
const A = jid("foo"); | ||
const B = jid("bar"); | ||
spy(A, "equals"); | ||
jid.equal(A, B); | ||
t.true(A.equals.calledWith(B)); | ||
A.equals.restore(); | ||
}); | ||
test('JID exports lib/JID', t => { | ||
t.is(jid.JID, JID) | ||
}) | ||
test("JID exports lib/JID", (t) => { | ||
t.is(jid.JID, JID); | ||
}); | ||
test('calls parse if only first argument provided', t => { | ||
const addr = jid('foo@bar') | ||
t.true(addr instanceof JID) | ||
t.is(addr.toString(), 'foo@bar') | ||
}) | ||
test("calls parse if only first argument provided", (t) => { | ||
const addr = jid("foo@bar"); | ||
t.true(addr instanceof JID); | ||
t.is(addr.toString(), "foo@bar"); | ||
}); | ||
test('calls JID with passed arguments', t => { | ||
const addr = jid('foo', 'bar', 'baz') | ||
t.true(addr instanceof JID) | ||
t.is(addr.toString(), 'foo@bar/baz') | ||
}) | ||
test("calls JID with passed arguments", (t) => { | ||
const addr = jid("foo", "bar", "baz"); | ||
t.true(addr instanceof JID); | ||
t.is(addr.toString(), "foo@bar/baz"); | ||
}); | ||
test('works as expected with new operator', t => { | ||
const addr = new jid('foo', 'bar', 'baz') // eslint-disable-line new-cap | ||
t.true(addr instanceof JID) | ||
t.is(addr.toString(), 'foo@bar/baz') | ||
}) | ||
test("works as expected with new operator", (t) => { | ||
const addr = new jid("foo", "bar", "baz"); // eslint-disable-line new-cap | ||
t.true(addr instanceof JID); | ||
t.is(addr.toString(), "foo@bar/baz"); | ||
}); |
@@ -1,14 +0,14 @@ | ||
'use strict' | ||
"use strict"; | ||
const test = require('ava') | ||
const JID = require('../lib/JID') | ||
const test = require("ava"); | ||
const JID = require("../lib/JID"); | ||
test('throws TypeError for invalid domain', t => { | ||
t.throws(() => new JID('foo'), {instanceOf: TypeError}) | ||
test("throws TypeError for invalid domain", (t) => { | ||
t.throws(() => new JID("foo"), { instanceOf: TypeError }); | ||
t.throws(() => new JID(), {instanceOf: TypeError}) | ||
t.throws(() => new JID(), { instanceOf: TypeError }); | ||
t.throws(() => new JID('foo', '', 'r'), {instanceOf: TypeError}) | ||
t.throws(() => new JID("foo", "", "r"), { instanceOf: TypeError }); | ||
t.throws(() => new JID('foo', '', 'r'), {instanceOf: TypeError}) | ||
}) | ||
t.throws(() => new JID("foo", "", "r"), { instanceOf: TypeError }); | ||
}); |
@@ -1,72 +0,72 @@ | ||
'use strict' | ||
"use strict"; | ||
const test = require('ava') | ||
const parse = require('../lib/parse') | ||
const test = require("ava"); | ||
const parse = require("../lib/parse"); | ||
test('should parse a "domain" JID', t => { | ||
const j = parse('d') | ||
t.is(j.getLocal(), '') | ||
t.is(j.getDomain(), 'd') | ||
t.is(j.getResource(), '') | ||
}) | ||
test('should parse a "domain" JID', (t) => { | ||
const j = parse("d"); | ||
t.is(j.getLocal(), ""); | ||
t.is(j.getDomain(), "d"); | ||
t.is(j.getResource(), ""); | ||
}); | ||
test('should parse a "user@domain" JID', t => { | ||
const j = parse('u@d') | ||
t.is(j.getLocal(), 'u') | ||
t.is(j.getDomain(), 'd') | ||
t.is(j.getResource(), '') | ||
}) | ||
test('should parse a "user@domain" JID', (t) => { | ||
const j = parse("u@d"); | ||
t.is(j.getLocal(), "u"); | ||
t.is(j.getDomain(), "d"); | ||
t.is(j.getResource(), ""); | ||
}); | ||
test('should parse a "domain/resource" JID', t => { | ||
const j = parse('d/r') | ||
t.is(j.getLocal(), '') | ||
t.is(j.getDomain(), 'd') | ||
t.is(j.getResource(), 'r') | ||
}) | ||
test('should parse a "domain/resource" JID', (t) => { | ||
const j = parse("d/r"); | ||
t.is(j.getLocal(), ""); | ||
t.is(j.getDomain(), "d"); | ||
t.is(j.getResource(), "r"); | ||
}); | ||
test('should parse a "user@domain/resource" JID', t => { | ||
const j = parse('u@d/r') | ||
t.is(j.getLocal(), 'u') | ||
t.is(j.getDomain(), 'd') | ||
t.is(j.getResource(), 'r') | ||
}) | ||
test('should parse a "user@domain/resource" JID', (t) => { | ||
const j = parse("u@d/r"); | ||
t.is(j.getLocal(), "u"); | ||
t.is(j.getDomain(), "d"); | ||
t.is(j.getResource(), "r"); | ||
}); | ||
test('should parse a "user@domain/resource@thing" JID', t => { | ||
const j = parse('u@d/r@foo') | ||
t.is(j.getLocal(), 'u') | ||
t.is(j.getDomain(), 'd') | ||
t.is(j.getResource(), 'r@foo') | ||
}) | ||
test('should parse a "user@domain/resource@thing" JID', (t) => { | ||
const j = parse("u@d/r@foo"); | ||
t.is(j.getLocal(), "u"); | ||
t.is(j.getDomain(), "d"); | ||
t.is(j.getResource(), "r@foo"); | ||
}); | ||
test('should parse a "user@domain/resource/thing" JID', t => { | ||
const j = parse('u@d/r/foo') | ||
t.is(j.getLocal(), 'u') | ||
t.is(j.getDomain(), 'd') | ||
t.is(j.getResource(), 'r/foo') | ||
}) | ||
test('should parse a "user@domain/resource/thing" JID', (t) => { | ||
const j = parse("u@d/r/foo"); | ||
t.is(j.getLocal(), "u"); | ||
t.is(j.getDomain(), "d"); | ||
t.is(j.getResource(), "r/foo"); | ||
}); | ||
test('should parse an internationalized domain name as unicode', t => { | ||
const j = parse('öko.de') | ||
t.is(j.getDomain(), 'öko.de') | ||
}) | ||
test("should parse an internationalized domain name as unicode", (t) => { | ||
const j = parse("öko.de"); | ||
t.is(j.getDomain(), "öko.de"); | ||
}); | ||
test('should parse an empty domain JID (#109)', t => { | ||
const j = parse('u@d', '') | ||
t.is(j.getLocal(), 'u') | ||
t.is(j.getDomain(), 'd') | ||
t.is(j.getResource(), '') | ||
}) | ||
test("should parse an empty domain JID (#109)", (t) => { | ||
const j = parse("u@d", ""); | ||
t.is(j.getLocal(), "u"); | ||
t.is(j.getDomain(), "d"); | ||
t.is(j.getResource(), ""); | ||
}); | ||
test('should allow access to jid parts using keys', t => { | ||
const j = parse('u@d/r', '') | ||
t.is(j.local, 'u') | ||
t.is(j.domain, 'd') | ||
t.is(j.resource, 'r') | ||
}) | ||
test("should allow access to jid parts using keys", (t) => { | ||
const j = parse("u@d/r", ""); | ||
t.is(j.local, "u"); | ||
t.is(j.domain, "d"); | ||
t.is(j.resource, "r"); | ||
}); | ||
test("shouldn't get U_STRINGPREP_PROHIBITED_ERROR (#93)", t => { | ||
test("shouldn't get U_STRINGPREP_PROHIBITED_ERROR (#93)", (t) => { | ||
t.notThrows(() => { | ||
const j = parse('f u@d') | ||
j.toString() | ||
}) | ||
}) | ||
const j = parse("f u@d"); | ||
j.toString(); | ||
}); | ||
}); |
@@ -1,24 +0,24 @@ | ||
'use strict' | ||
"use strict"; | ||
const test = require('ava') | ||
const JID = require('../lib/JID') | ||
const test = require("ava"); | ||
const JID = require("../lib/JID"); | ||
test('should serialize a "domain" JID', t => { | ||
const j = new JID(null, 'd') | ||
t.is(j.toString(), 'd') | ||
}) | ||
test('should serialize a "domain" JID', (t) => { | ||
const j = new JID(null, "d"); | ||
t.is(j.toString(), "d"); | ||
}); | ||
test('should serialize a "user@domain" JID', t => { | ||
const j = new JID('u', 'd') | ||
t.is(j.toString(), 'u@d') | ||
}) | ||
test('should serialize a "user@domain" JID', (t) => { | ||
const j = new JID("u", "d"); | ||
t.is(j.toString(), "u@d"); | ||
}); | ||
test('should serialize a "domain/resource" JID', t => { | ||
const j = new JID(null, 'd', 'r') | ||
t.is(j.toString(), 'd/r') | ||
}) | ||
test('should serialize a "domain/resource" JID', (t) => { | ||
const j = new JID(null, "d", "r"); | ||
t.is(j.toString(), "d/r"); | ||
}); | ||
test('should serialize a "user@domain/resource" JID', t => { | ||
const j = new JID('u', 'd', 'r') | ||
t.is(j.toString(), 'u@d/r') | ||
}) | ||
test('should serialize a "user@domain/resource" JID', (t) => { | ||
const j = new JID("u", "d", "r"); | ||
t.is(j.toString(), "u@d/r"); | ||
}); |
@@ -1,19 +0,19 @@ | ||
'use strict' | ||
"use strict"; | ||
const test = require('ava') | ||
const JID = require('../lib/JID') | ||
const test = require("ava"); | ||
const JID = require("../lib/JID"); | ||
/* eslint-disable no-implicit-coercion, eqeqeq */ | ||
test('cocerce to string', t => { | ||
const addr = new JID('foo', 'bar') | ||
t.is(addr + '', addr.toString()) | ||
t.is('' + addr, addr.toString()) | ||
t.true(addr == addr.toString()) | ||
}) | ||
test("cocerce to string", (t) => { | ||
const addr = new JID("foo", "bar"); | ||
t.is(addr + "", addr.toString()); | ||
t.is("" + addr, addr.toString()); | ||
t.true(addr == addr.toString()); | ||
}); | ||
test('cocerce to NaN', t => { | ||
const addr = new JID('foo', 'bar') | ||
t.true(isNaN(+addr)) | ||
t.true(isNaN(addr + 4)) | ||
}) | ||
test("cocerce to NaN", (t) => { | ||
const addr = new JID("foo", "bar"); | ||
t.true(isNaN(+addr)); | ||
t.true(isNaN(addr + 4)); | ||
}); |
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
Found 1 instance in 1 package
19722
513
1