2020-12-14 00:04:38 +00:00
|
|
|
'use strict';
|
|
|
|
|
2020-11-23 18:21:51 +00:00
|
|
|
describe('urls', function () {
|
2020-12-14 00:04:38 +00:00
|
|
|
// Returns the first text element. Note that any change to the text element will result in the
|
|
|
|
// element being replaced with another object.
|
|
|
|
const txt = () => helper.padInner$('div').first();
|
|
|
|
|
|
|
|
before(async function () {
|
2012-11-01 23:19:59 +00:00
|
|
|
this.timeout(60000);
|
2020-12-14 00:04:38 +00:00
|
|
|
await new Promise((resolve, reject) => helper.newPad((err) => {
|
|
|
|
if (err != null) return reject(err);
|
|
|
|
resolve();
|
|
|
|
}));
|
2012-10-03 20:55:23 +00:00
|
|
|
});
|
|
|
|
|
2020-12-14 00:04:38 +00:00
|
|
|
beforeEach(async function () {
|
|
|
|
await helper.clearPad();
|
2012-10-03 20:55:23 +00:00
|
|
|
});
|
2012-11-21 17:52:10 +00:00
|
|
|
|
2020-12-14 00:04:38 +00:00
|
|
|
describe('entering a URL makes a link', function () {
|
|
|
|
for (const url of ['https://etherpad.org', 'www.etherpad.org']) {
|
|
|
|
it(url, async function () {
|
|
|
|
const url = 'https://etherpad.org';
|
|
|
|
await helper.edit(url);
|
|
|
|
await helper.waitForPromise(() => txt().find('a').length === 1, 2000);
|
|
|
|
const link = txt().find('a');
|
|
|
|
expect(link.attr('href')).to.be(url);
|
|
|
|
expect(link.text()).to.be(url);
|
|
|
|
});
|
|
|
|
}
|
2012-11-21 17:52:10 +00:00
|
|
|
});
|
|
|
|
|
2020-12-14 00:04:38 +00:00
|
|
|
describe('special characters inside URL', function () {
|
2020-12-12 23:26:48 +00:00
|
|
|
for (const char of '-:@_.,~%+/?=&#!;()$\'*') {
|
2020-12-14 00:04:38 +00:00
|
|
|
const url = `https://etherpad.org/${char}foo`;
|
|
|
|
it(url, async function () {
|
|
|
|
await helper.edit(url);
|
|
|
|
await helper.waitForPromise(() => txt().find('a').length === 1);
|
|
|
|
const link = txt().find('a');
|
|
|
|
expect(link.attr('href')).to.be(url);
|
|
|
|
expect(link.text()).to.be(url);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2016-06-27 20:20:12 +00:00
|
|
|
|
2020-12-14 00:04:38 +00:00
|
|
|
describe('punctuation after URL is ignored', function () {
|
2020-12-12 23:26:48 +00:00
|
|
|
for (const char of ':.,;?!)\'*]') {
|
2020-12-14 00:04:38 +00:00
|
|
|
const want = 'https://etherpad.org';
|
|
|
|
const input = want + char;
|
|
|
|
it(input, async function () {
|
|
|
|
await helper.edit(input);
|
|
|
|
await helper.waitForPromise(() => txt().find('a').length === 1);
|
|
|
|
const link = txt().find('a');
|
|
|
|
expect(link.attr('href')).to.be(want);
|
|
|
|
expect(link.text()).to.be(want);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
});
|
2016-06-27 20:20:12 +00:00
|
|
|
|
2020-12-14 00:04:38 +00:00
|
|
|
// Square brackets are in the RFC3986 reserved set so they can legally appear in URIs, but they
|
|
|
|
// are explicitly excluded from linkification because including them is usually not desired (e.g.,
|
|
|
|
// it can interfere with wiki/markdown link syntax).
|
|
|
|
describe('square brackets are excluded from linkified URLs', function () {
|
|
|
|
for (const char of '[]') {
|
|
|
|
const want = 'https://etherpad.org/';
|
|
|
|
const input = `${want}${char}foo`;
|
|
|
|
it(input, async function () {
|
|
|
|
await helper.edit(input);
|
|
|
|
await helper.waitForPromise(() => txt().find('a').length === 1);
|
|
|
|
const link = txt().find('a');
|
|
|
|
expect(link.attr('href')).to.be(want);
|
|
|
|
expect(link.text()).to.be(want);
|
|
|
|
});
|
|
|
|
}
|
2016-06-27 20:20:12 +00:00
|
|
|
});
|
2012-10-03 20:55:23 +00:00
|
|
|
});
|