Skip to content

Commit

Permalink
Added unit tests for XEP-0106 JID espcaping Transaformation function
Browse files Browse the repository at this point in the history
  • Loading branch information
rakaar committed Jan 29, 2020
1 parent 45a8d81 commit 89915a2
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 1 deletion.
3 changes: 2 additions & 1 deletion src/MatrixRoomHandler.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ const XEP0106_ESCAPING_TRANSFORMATIONS = {
":": "\3a",
"<": "\3c",
">": "\3e",
"@": "\40"
"@": "\40",
" ": "\20"
}

export function XEP0106ApplyEscapingTransformations(roomId: string): string {
Expand Down
22 changes: 22 additions & 0 deletions test/test_matrixroomhandler.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// tslint:disable: no-any
import * as Chai from "chai";
import { XEP0106ApplyEscapingTransformations } from "../src/MatrixRoomHandler";
const expect = Chai.expect;

describe('XEP0106JIDEscaping', () => {
it('implement XEP-0106 JID escaping for matrix room ID', () => {
expect(XEP0106ApplyEscapingTransformations('space [email protected]')).to.equal('space\[email protected]');
expect(XEP0106ApplyEscapingTransformations('call me "ishmael"@example.com')).to.equal('call\20me\20\22ishmael\[email protected]');
expect(XEP0106ApplyEscapingTransformations('at&t [email protected]')).to.equal('at\26t\[email protected]');
expect(XEP0106ApplyEscapingTransformations('d\'[email protected]')).to.equal('d\[email protected]');
expect(XEP0106ApplyEscapingTransformations('/[email protected]')).to.equal('\[email protected]');
expect(XEP0106ApplyEscapingTransformations('::foo::@example.com')).to.equal('\3a\3afoo\3a\[email protected]');
expect(XEP0106ApplyEscapingTransformations('<foo>@example.com')).to.equal('\3cfoo\[email protected]');
expect(XEP0106ApplyEscapingTransformations('user@[email protected]')).to.equal('user\[email protected]');
expect(XEP0106ApplyEscapingTransformations('c:\\[email protected]')).to.equal('c\3a\[email protected]');
expect(XEP0106ApplyEscapingTransformations('c:\\\\[email protected]')).to.equal('c\3a\\[email protected]');
expect(XEP0106ApplyEscapingTransformations('c:\\cool [email protected]')).to.equal('c\3a\cool\[email protected]');
expect(XEP0106ApplyEscapingTransformations('c:\\[email protected]')).to.equal('c\3a\[email protected]');

})
})

0 comments on commit 89915a2

Please sign in to comment.