2017-03-18 08:18:47 +00:00
|
|
|
|
"use strict";
|
|
|
|
|
|
|
|
|
|
const expect = require("chai").expect;
|
|
|
|
|
const parse = require("../../../../../client/js/libs/handlebars/parse");
|
|
|
|
|
|
|
|
|
|
describe("parse Handlebars helper", () => {
|
|
|
|
|
it("should not introduce xss", () => {
|
|
|
|
|
const testCases = [{
|
|
|
|
|
input: "<img onerror='location.href=\"//youtube.com\"'>",
|
2017-11-15 06:35:15 +00:00
|
|
|
|
expected: "<img onerror='location.href="//youtube.com"'>",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}, {
|
2017-11-26 22:34:28 +00:00
|
|
|
|
input: '#&">bug',
|
|
|
|
|
expected: '<span class="inline-channel" role="button" tabindex="0" data-chan="#&">bug">#&">bug</span>',
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}];
|
|
|
|
|
|
2017-04-08 12:34:31 +00:00
|
|
|
|
const actual = testCases.map((testCase) => parse(testCase.input));
|
|
|
|
|
const expected = testCases.map((testCase) => testCase.expected);
|
2017-03-18 08:18:47 +00:00
|
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should skip control codes", () => {
|
|
|
|
|
const testCases = [{
|
|
|
|
|
input: "text\x01with\x04control\x05codes",
|
2017-11-15 06:35:15 +00:00
|
|
|
|
expected: "textwithcontrolcodes",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}];
|
|
|
|
|
|
2017-04-08 12:34:31 +00:00
|
|
|
|
const actual = testCases.map((testCase) => parse(testCase.input));
|
|
|
|
|
const expected = testCases.map((testCase) => testCase.expected);
|
2017-03-18 08:18:47 +00:00
|
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should find urls", () => {
|
|
|
|
|
const testCases = [{
|
|
|
|
|
input: "irc://freenode.net/thelounge",
|
|
|
|
|
expected:
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<a href="irc://freenode.net/thelounge" target="_blank" rel="noopener">' +
|
2017-03-18 08:18:47 +00:00
|
|
|
|
"irc://freenode.net/thelounge" +
|
2017-11-15 06:35:15 +00:00
|
|
|
|
"</a>",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}, {
|
|
|
|
|
input: "www.nooooooooooooooo.com",
|
|
|
|
|
expected:
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<a href="http://www.nooooooooooooooo.com" target="_blank" rel="noopener">' +
|
2017-03-18 08:18:47 +00:00
|
|
|
|
"www.nooooooooooooooo.com" +
|
2017-11-15 06:35:15 +00:00
|
|
|
|
"</a>",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}, {
|
|
|
|
|
input: "look at https://thelounge.github.io/ for more information",
|
|
|
|
|
expected:
|
|
|
|
|
"look at " +
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<a href="https://thelounge.github.io/" target="_blank" rel="noopener">' +
|
2017-03-18 08:18:47 +00:00
|
|
|
|
"https://thelounge.github.io/" +
|
|
|
|
|
"</a>" +
|
2017-11-15 06:35:15 +00:00
|
|
|
|
" for more information",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}, {
|
|
|
|
|
input: "use www.duckduckgo.com for privacy reasons",
|
|
|
|
|
expected:
|
|
|
|
|
"use " +
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<a href="http://www.duckduckgo.com" target="_blank" rel="noopener">' +
|
2017-03-18 08:18:47 +00:00
|
|
|
|
"www.duckduckgo.com" +
|
|
|
|
|
"</a>" +
|
2017-11-15 06:35:15 +00:00
|
|
|
|
" for privacy reasons",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}, {
|
|
|
|
|
input: "svn+ssh://example.org",
|
|
|
|
|
expected:
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<a href="svn+ssh://example.org" target="_blank" rel="noopener">' +
|
2017-03-18 08:18:47 +00:00
|
|
|
|
"svn+ssh://example.org" +
|
2017-11-15 06:35:15 +00:00
|
|
|
|
"</a>",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}];
|
|
|
|
|
|
2017-04-08 12:34:31 +00:00
|
|
|
|
const actual = testCases.map((testCase) => parse(testCase.input));
|
|
|
|
|
const expected = testCases.map((testCase) => testCase.expected);
|
2017-03-18 08:18:47 +00:00
|
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("url with a dot parsed correctly", () => {
|
|
|
|
|
const input =
|
|
|
|
|
"bonuspunkt: your URL parser misparses this URL: https://msdn.microsoft.com/en-us/library/windows/desktop/ms644989(v=vs.85).aspx";
|
|
|
|
|
const correctResult =
|
|
|
|
|
"bonuspunkt: your URL parser misparses this URL: " +
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<a href="https://msdn.microsoft.com/en-us/library/windows/desktop/ms644989(v=vs.85).aspx" target="_blank" rel="noopener">' +
|
2017-03-18 08:18:47 +00:00
|
|
|
|
"https://msdn.microsoft.com/en-us/library/windows/desktop/ms644989(v=vs.85).aspx" +
|
2017-07-19 05:26:29 +00:00
|
|
|
|
"</a>";
|
2017-03-18 08:18:47 +00:00
|
|
|
|
|
|
|
|
|
const actual = parse(input);
|
|
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(correctResult);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should balance brackets", () => {
|
|
|
|
|
const testCases = [{
|
|
|
|
|
input: "<https://theos.kyriasis.com/~kyrias/stats/archlinux.html>",
|
|
|
|
|
expected:
|
|
|
|
|
"<" +
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<a href="https://theos.kyriasis.com/~kyrias/stats/archlinux.html" target="_blank" rel="noopener">' +
|
2017-03-18 08:18:47 +00:00
|
|
|
|
"https://theos.kyriasis.com/~kyrias/stats/archlinux.html" +
|
|
|
|
|
"</a>" +
|
2017-11-15 06:35:15 +00:00
|
|
|
|
">",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}, {
|
|
|
|
|
input: "abc (www.example.com)",
|
|
|
|
|
expected:
|
|
|
|
|
"abc (" +
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<a href="http://www.example.com" target="_blank" rel="noopener">' +
|
2017-03-18 08:18:47 +00:00
|
|
|
|
"www.example.com" +
|
|
|
|
|
"</a>" +
|
2017-11-15 06:35:15 +00:00
|
|
|
|
")",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}, {
|
|
|
|
|
input: "http://example.com/Test_(Page)",
|
|
|
|
|
expected:
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<a href="http://example.com/Test_(Page)" target="_blank" rel="noopener">' +
|
2017-03-18 08:18:47 +00:00
|
|
|
|
"http://example.com/Test_(Page)" +
|
2017-11-15 06:35:15 +00:00
|
|
|
|
"</a>",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}, {
|
|
|
|
|
input: "www.example.com/Test_(Page)",
|
|
|
|
|
expected:
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<a href="http://www.example.com/Test_(Page)" target="_blank" rel="noopener">' +
|
2017-03-18 08:18:47 +00:00
|
|
|
|
"www.example.com/Test_(Page)" +
|
2017-11-15 06:35:15 +00:00
|
|
|
|
"</a>",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}];
|
|
|
|
|
|
2017-04-08 12:34:31 +00:00
|
|
|
|
const actual = testCases.map((testCase) => parse(testCase.input));
|
|
|
|
|
const expected = testCases.map((testCase) => testCase.expected);
|
2017-03-18 08:18:47 +00:00
|
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should not find urls", () => {
|
|
|
|
|
const testCases = [{
|
|
|
|
|
input: "text www. text",
|
2017-11-15 06:35:15 +00:00
|
|
|
|
expected: "text www. text",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}, {
|
|
|
|
|
input: "http://.",
|
2017-11-15 06:35:15 +00:00
|
|
|
|
expected: "http://.",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}];
|
|
|
|
|
|
2017-04-08 12:34:31 +00:00
|
|
|
|
const actual = testCases.map((testCase) => parse(testCase.input));
|
|
|
|
|
const expected = testCases.map((testCase) => testCase.expected);
|
2017-03-18 08:18:47 +00:00
|
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should find channels", () => {
|
|
|
|
|
const testCases = [{
|
|
|
|
|
input: "#a",
|
|
|
|
|
expected:
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<span class="inline-channel" role="button" tabindex="0" data-chan="#a">' +
|
2017-03-18 08:18:47 +00:00
|
|
|
|
"#a" +
|
2017-11-15 06:35:15 +00:00
|
|
|
|
"</span>",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}, {
|
|
|
|
|
input: "#test",
|
|
|
|
|
expected:
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<span class="inline-channel" role="button" tabindex="0" data-chan="#test">' +
|
2017-03-18 08:18:47 +00:00
|
|
|
|
"#test" +
|
2017-11-15 06:35:15 +00:00
|
|
|
|
"</span>",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}, {
|
|
|
|
|
input: "#äöü",
|
|
|
|
|
expected:
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<span class="inline-channel" role="button" tabindex="0" data-chan="#äöü">' +
|
2017-03-18 08:18:47 +00:00
|
|
|
|
"#äöü" +
|
2017-11-15 06:35:15 +00:00
|
|
|
|
"</span>",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}, {
|
|
|
|
|
input: "inline #channel text",
|
|
|
|
|
expected:
|
|
|
|
|
"inline " +
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<span class="inline-channel" role="button" tabindex="0" data-chan="#channel">' +
|
2017-03-18 08:18:47 +00:00
|
|
|
|
"#channel" +
|
|
|
|
|
"</span>" +
|
2017-11-15 06:35:15 +00:00
|
|
|
|
" text",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}, {
|
|
|
|
|
input: "#1,000",
|
|
|
|
|
expected:
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<span class="inline-channel" role="button" tabindex="0" data-chan="#1,000">' +
|
2017-03-18 08:18:47 +00:00
|
|
|
|
"#1,000" +
|
2017-11-15 06:35:15 +00:00
|
|
|
|
"</span>",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}, {
|
|
|
|
|
input: "@#a",
|
|
|
|
|
expected:
|
|
|
|
|
"@" +
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<span class="inline-channel" role="button" tabindex="0" data-chan="#a">' +
|
2017-03-18 08:18:47 +00:00
|
|
|
|
"#a" +
|
2017-11-15 06:35:15 +00:00
|
|
|
|
"</span>",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}];
|
|
|
|
|
|
2017-04-08 12:34:31 +00:00
|
|
|
|
const actual = testCases.map((testCase) => parse(testCase.input));
|
|
|
|
|
const expected = testCases.map((testCase) => testCase.expected);
|
2017-03-18 08:18:47 +00:00
|
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should not find channels", () => {
|
|
|
|
|
const testCases = [{
|
|
|
|
|
input: "hi#test",
|
2017-11-15 06:35:15 +00:00
|
|
|
|
expected: "hi#test",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}, {
|
|
|
|
|
input: "#",
|
2017-11-15 06:35:15 +00:00
|
|
|
|
expected: "#",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}];
|
|
|
|
|
|
2017-04-08 12:34:31 +00:00
|
|
|
|
const actual = testCases.map((testCase) => parse(testCase.input));
|
|
|
|
|
const expected = testCases.map((testCase) => testCase.expected);
|
2017-03-18 08:18:47 +00:00
|
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
|
});
|
|
|
|
|
|
2017-11-29 05:31:03 +00:00
|
|
|
|
[{
|
|
|
|
|
name: "bold",
|
|
|
|
|
input: "\x02bold",
|
|
|
|
|
expected: '<span class="irc-bold">bold</span>',
|
|
|
|
|
}, {
|
|
|
|
|
name: "foreground color",
|
|
|
|
|
input: "\x038yellowText",
|
|
|
|
|
expected: '<span class="irc-fg8">yellowText</span>',
|
|
|
|
|
}, {
|
|
|
|
|
name: "foreground and background colors (white)",
|
|
|
|
|
input: "\x030,0white,white",
|
|
|
|
|
expected: '<span class="irc-fg0 irc-bg0">white,white</span>',
|
|
|
|
|
}, {
|
|
|
|
|
name: "foreground and background colors",
|
|
|
|
|
input: "\x034,8yellowBGredText",
|
|
|
|
|
expected: '<span class="irc-fg4 irc-bg8">yellowBGredText</span>',
|
|
|
|
|
}, {
|
|
|
|
|
name: "hex foreground color",
|
|
|
|
|
input: "\x04663399rebeccapurple",
|
|
|
|
|
expected: '<span style="color:#663399">rebeccapurple</span>',
|
|
|
|
|
}, {
|
|
|
|
|
name: "hex foreground and background colors",
|
|
|
|
|
input: "\x04415364,ff9e18The Lounge",
|
|
|
|
|
expected: '<span style="color:#415364;background-color:#FF9E18">The Lounge</span>',
|
|
|
|
|
}, {
|
|
|
|
|
name: "italic",
|
|
|
|
|
input: "\x1ditalic",
|
|
|
|
|
expected: '<span class="irc-italic">italic</span>',
|
|
|
|
|
}, {
|
|
|
|
|
name: "underline",
|
|
|
|
|
input: "\x1funderline",
|
|
|
|
|
expected: '<span class="irc-underline">underline</span>',
|
2017-12-03 02:52:49 +00:00
|
|
|
|
}, {
|
|
|
|
|
name: "strikethrough",
|
|
|
|
|
input: "\x1estrikethrough",
|
|
|
|
|
expected: '<span class="irc-strikethrough">strikethrough</span>',
|
2017-12-03 15:00:35 +00:00
|
|
|
|
}, {
|
|
|
|
|
name: "monospace",
|
|
|
|
|
input: "\x11monospace",
|
|
|
|
|
expected: '<span class="irc-monospace">monospace</span>',
|
2017-11-29 05:31:03 +00:00
|
|
|
|
}, {
|
|
|
|
|
name: "resets",
|
|
|
|
|
input: "\x02bold\x038yellow\x02nonBold\x03default",
|
|
|
|
|
expected:
|
|
|
|
|
'<span class="irc-bold">bold</span>' +
|
|
|
|
|
'<span class="irc-bold irc-fg8">yellow</span>' +
|
|
|
|
|
'<span class="irc-fg8">nonBold</span>' +
|
|
|
|
|
"default",
|
|
|
|
|
}, {
|
|
|
|
|
name: "duplicates",
|
|
|
|
|
input: "\x02bold\x02 \x02bold\x02",
|
|
|
|
|
expected:
|
|
|
|
|
'<span class="irc-bold">bold</span>' +
|
|
|
|
|
" " +
|
|
|
|
|
'<span class="irc-bold">bold</span>',
|
|
|
|
|
}].forEach((item) => { // TODO: In Node v6+, use `{name, input, expected}`
|
|
|
|
|
it(`should handle style characters: ${item.name}`, function() {
|
|
|
|
|
expect(parse(item.input)).to.equal(item.expected);
|
|
|
|
|
});
|
2017-03-18 08:18:47 +00:00
|
|
|
|
});
|
|
|
|
|
|
2017-11-14 22:36:45 +00:00
|
|
|
|
it("should find nicks", () => {
|
|
|
|
|
const testCases = [{
|
|
|
|
|
users: ["MaxLeiter"],
|
|
|
|
|
input: "test, MaxLeiter",
|
|
|
|
|
expected:
|
|
|
|
|
"test, " +
|
2017-11-27 23:40:23 +00:00
|
|
|
|
'<span role="button" class="user color-12" data-name="MaxLeiter">' +
|
2017-11-14 22:36:45 +00:00
|
|
|
|
"MaxLeiter" +
|
|
|
|
|
"</span>",
|
|
|
|
|
}];
|
|
|
|
|
|
|
|
|
|
const actual = testCases.map((testCase) => parse(testCase.input, testCase.users));
|
|
|
|
|
const expected = testCases.map((testCase) => testCase.expected);
|
|
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should not find nicks", () => {
|
|
|
|
|
const testCases = [{
|
|
|
|
|
users: ["MaxLeiter, test"],
|
|
|
|
|
input: "#test-channelMaxLeiter",
|
|
|
|
|
expected:
|
2017-11-27 23:40:23 +00:00
|
|
|
|
'<span class="inline-channel" role="button" tabindex="0" data-chan="#test-channelMaxLeiter">' +
|
2017-11-14 22:36:45 +00:00
|
|
|
|
"#test-channelMaxLeiter" +
|
|
|
|
|
"</span>",
|
|
|
|
|
},
|
|
|
|
|
{
|
|
|
|
|
users: ["MaxLeiter, test"],
|
|
|
|
|
input: "https://www.MaxLeiter.com/test",
|
|
|
|
|
expected:
|
2017-11-27 23:40:23 +00:00
|
|
|
|
'<a href="https://www.MaxLeiter.com/test" target="_blank" rel="noopener">' +
|
2017-11-14 22:36:45 +00:00
|
|
|
|
"https://www.MaxLeiter.com/test" +
|
|
|
|
|
"</a>",
|
|
|
|
|
},
|
|
|
|
|
|
|
|
|
|
];
|
|
|
|
|
|
|
|
|
|
const actual = testCases.map((testCase) => parse(testCase.input));
|
|
|
|
|
const expected = testCases.map((testCase) => testCase.expected);
|
|
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
|
});
|
|
|
|
|
|
2017-03-18 08:18:47 +00:00
|
|
|
|
it("should go bonkers like mirc", () => {
|
|
|
|
|
const testCases = [{
|
|
|
|
|
input: "\x02irc\x0f://\x1dfreenode.net\x0f/\x034,8thelounge",
|
|
|
|
|
expected:
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<a href="irc://freenode.net/thelounge" target="_blank" rel="noopener">' +
|
|
|
|
|
'<span class="irc-bold">irc</span>' +
|
2017-03-18 08:18:47 +00:00
|
|
|
|
"://" +
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<span class="irc-italic">freenode.net</span>' +
|
2017-03-18 08:18:47 +00:00
|
|
|
|
"/" +
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<span class="irc-fg4 irc-bg8">thelounge</span>' +
|
2017-11-15 06:35:15 +00:00
|
|
|
|
"</a>",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}, {
|
|
|
|
|
input: "\x02#\x038,9thelounge",
|
|
|
|
|
expected:
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<span class="inline-channel" role="button" tabindex="0" data-chan="#thelounge">' +
|
|
|
|
|
'<span class="irc-bold">#</span>' +
|
|
|
|
|
'<span class="irc-bold irc-fg8 irc-bg9">thelounge</span>' +
|
2017-11-15 06:35:15 +00:00
|
|
|
|
"</span>",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}];
|
|
|
|
|
|
2017-04-08 12:34:31 +00:00
|
|
|
|
const actual = testCases.map((testCase) => parse(testCase.input));
|
|
|
|
|
const expected = testCases.map((testCase) => testCase.expected);
|
2017-03-18 08:18:47 +00:00
|
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
|
});
|
|
|
|
|
|
2017-11-29 05:31:03 +00:00
|
|
|
|
// Emoji
|
|
|
|
|
[{
|
|
|
|
|
name: "in text",
|
|
|
|
|
input: "Hello💬",
|
|
|
|
|
expected: 'Hello<span class="emoji">💬</span>',
|
|
|
|
|
}, {
|
|
|
|
|
name: "with modifiers",
|
|
|
|
|
input: "🤷♀️",
|
|
|
|
|
expected: '<span class="emoji">🤷♀️</span>',
|
|
|
|
|
}, {
|
|
|
|
|
// FIXME: These multiple `span`s should be optimized into a single one. See https://github.com/thelounge/lounge/issues/1783
|
|
|
|
|
name: "wrapped in style",
|
|
|
|
|
input: "Super \x034💚 green!",
|
|
|
|
|
expected: 'Super <span class="emoji"><span class="irc-fg4">💚</span></span><span class="irc-fg4"> green!</span>',
|
|
|
|
|
}, {
|
|
|
|
|
name: "wrapped in URLs",
|
|
|
|
|
input: "https://i.❤️.thelounge.chat",
|
|
|
|
|
// FIXME: Emoji in text should be `<span class="emoji">❤️</span>`. See https://github.com/thelounge/lounge/issues/1784
|
|
|
|
|
expected: '<a href="https://i.❤️.thelounge.chat" target="_blank" rel="noopener">https://i.❤️.thelounge.chat</a>',
|
|
|
|
|
}, {
|
|
|
|
|
name: "wrapped in channels",
|
|
|
|
|
input: "#i❤️thelounge",
|
|
|
|
|
// FIXME: Emoji in text should be `<span class="emoji">❤️</span>`. See https://github.com/thelounge/lounge/issues/1784
|
|
|
|
|
expected: '<span class="inline-channel" role="button" tabindex="0" data-chan="#i❤️thelounge">#i❤️thelounge</span>',
|
|
|
|
|
}].forEach((item) => { // TODO: In Node v6+, use `{name, input, expected}`
|
|
|
|
|
it(`should find emoji: ${item.name}`, function() {
|
|
|
|
|
expect(parse(item.input)).to.equal(item.expected);
|
|
|
|
|
});
|
|
|
|
|
});
|
|
|
|
|
|
2017-03-18 08:18:47 +00:00
|
|
|
|
it("should optimize generated html", () => {
|
|
|
|
|
const testCases = [{
|
2017-11-26 22:34:28 +00:00
|
|
|
|
input: 'test \x0312#\x0312\x0312"te\x0312st\x0312\x0312\x0312\x0312\x0312\x0312\x0312\x0312\x0312\x0312\x0312a',
|
2017-03-18 08:18:47 +00:00
|
|
|
|
expected:
|
|
|
|
|
"test " +
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<span class="inline-channel" role="button" tabindex="0" data-chan="#"testa">' +
|
|
|
|
|
'<span class="irc-fg12">#"testa</span>' +
|
2017-11-15 06:35:15 +00:00
|
|
|
|
"</span>",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}];
|
|
|
|
|
|
2017-04-08 12:34:31 +00:00
|
|
|
|
const actual = testCases.map((testCase) => parse(testCase.input));
|
|
|
|
|
const expected = testCases.map((testCase) => testCase.expected);
|
2017-03-18 08:18:47 +00:00
|
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
|
});
|
|
|
|
|
|
2017-08-25 15:58:16 +00:00
|
|
|
|
it("should trim common protocols", () => {
|
2017-03-18 08:18:47 +00:00
|
|
|
|
const testCases = [{
|
|
|
|
|
input: "like..http://example.com",
|
|
|
|
|
expected:
|
|
|
|
|
"like.." +
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<a href="http://example.com" target="_blank" rel="noopener">' +
|
2017-03-18 08:18:47 +00:00
|
|
|
|
"http://example.com" +
|
2017-11-15 06:35:15 +00:00
|
|
|
|
"</a>",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}, {
|
|
|
|
|
input: "like..HTTP://example.com",
|
|
|
|
|
expected:
|
|
|
|
|
"like.." +
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<a href="HTTP://example.com" target="_blank" rel="noopener">' +
|
2017-03-18 08:18:47 +00:00
|
|
|
|
"HTTP://example.com" +
|
2017-11-15 06:35:15 +00:00
|
|
|
|
"</a>",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}];
|
|
|
|
|
|
2017-04-08 12:34:31 +00:00
|
|
|
|
const actual = testCases.map((testCase) => parse(testCase.input));
|
|
|
|
|
const expected = testCases.map((testCase) => testCase.expected);
|
2017-03-18 08:18:47 +00:00
|
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should not find channel in fragment", () => {
|
|
|
|
|
const testCases = [{
|
|
|
|
|
input: "http://example.com/#hash",
|
|
|
|
|
expected:
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<a href="http://example.com/#hash" target="_blank" rel="noopener">' +
|
2017-03-18 08:18:47 +00:00
|
|
|
|
"http://example.com/#hash" +
|
2017-11-15 06:35:15 +00:00
|
|
|
|
"</a>",
|
2017-03-18 08:18:47 +00:00
|
|
|
|
}];
|
|
|
|
|
|
2017-04-08 12:34:31 +00:00
|
|
|
|
const actual = testCases.map((testCase) => parse(testCase.input));
|
|
|
|
|
const expected = testCases.map((testCase) => testCase.expected);
|
2017-03-18 08:18:47 +00:00
|
|
|
|
|
|
|
|
|
expect(actual).to.deep.equal(expected);
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
it("should not overlap parts", () => {
|
|
|
|
|
const input = "Url: http://example.com/path Channel: ##channel";
|
|
|
|
|
const actual = parse(input);
|
|
|
|
|
|
|
|
|
|
expect(actual).to.equal(
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'Url: <a href="http://example.com/path" target="_blank" rel="noopener">http://example.com/path</a> ' +
|
|
|
|
|
'Channel: <span class="inline-channel" role="button" tabindex="0" data-chan="##channel">##channel</span>'
|
2017-03-18 08:18:47 +00:00
|
|
|
|
);
|
|
|
|
|
});
|
2017-11-26 19:26:59 +00:00
|
|
|
|
|
|
|
|
|
it("should handle overlapping parts by using first starting", () => {
|
|
|
|
|
const input = "#test-https://example.com";
|
|
|
|
|
const actual = parse(input);
|
|
|
|
|
|
|
|
|
|
expect(actual).to.equal(
|
2017-11-26 22:34:28 +00:00
|
|
|
|
'<span class="inline-channel" role="button" tabindex="0" data-chan="#test-https://example.com">' +
|
2017-11-26 19:26:59 +00:00
|
|
|
|
"#test-https://example.com" +
|
|
|
|
|
"</span>"
|
|
|
|
|
);
|
|
|
|
|
});
|
2017-03-18 08:18:47 +00:00
|
|
|
|
});
|