Users can add any website as a dashboard quick link from Settings → Site Links. The link is stored in the integrations namespace as a `custom` type so it flows through the existing sites/integrations/settings pipeline, and appears in a new "Links" group. Its icon is discovered with the existing favicon pipeline; an uploaded icon overrides it and stays pinned until the user chooses "Use site's icon" again. resolveIcons and refreshIcon skip pinned sites (and re-check the live list before writing back) so an in-flight discovery can never clobber a freshly uploaded icon. URLs are normalized to http(s) only, with embedded credentials stripped, so a value can never reach an anchor's href as javascript:/data:. Uploads are validated, size-capped and downscaled to 192px (SVGs kept as-is), and only ever rendered through an <img>. Adds app/utils/site-url.js and app/utils/image-file.js, a custom-link form, a `custom` registry entry/group and adapter, and tests.
56 lines
1.8 KiB
JavaScript
56 lines
1.8 KiB
JavaScript
import { module, test } from 'qunit';
|
|
import { labelForUrl, normalizeSiteUrl } from 'dashtab/utils/site-url';
|
|
|
|
module('Unit | Utility | site-url', function () {
|
|
test('prepends https when no scheme is given', function (assert) {
|
|
assert.strictEqual(normalizeSiteUrl('example.com'), 'https://example.com/');
|
|
assert.strictEqual(
|
|
normalizeSiteUrl('example.com/path'),
|
|
'https://example.com/path'
|
|
);
|
|
assert.strictEqual(
|
|
normalizeSiteUrl('example.com:8080'),
|
|
'https://example.com:8080/'
|
|
);
|
|
});
|
|
|
|
test('keeps an explicit http(s) URL and its path, query and port', function (assert) {
|
|
assert.strictEqual(
|
|
normalizeSiteUrl('http://example.com'),
|
|
'http://example.com/'
|
|
);
|
|
assert.strictEqual(
|
|
normalizeSiteUrl('https://example.com:8080/a?b=1'),
|
|
'https://example.com:8080/a?b=1'
|
|
);
|
|
});
|
|
|
|
test('rejects non-http(s) schemes', function (assert) {
|
|
assert.strictEqual(normalizeSiteUrl('ftp://example.com'), null);
|
|
assert.strictEqual(normalizeSiteUrl('javascript:alert(1)'), null);
|
|
assert.strictEqual(normalizeSiteUrl('data:text/html,hi'), null);
|
|
});
|
|
|
|
test('strips embedded credentials', function (assert) {
|
|
assert.strictEqual(
|
|
normalizeSiteUrl('https://user:pass@example.com/path'),
|
|
'https://example.com/path'
|
|
);
|
|
});
|
|
|
|
test('rejects empty, whitespace and unparseable values', function (assert) {
|
|
assert.strictEqual(normalizeSiteUrl(''), null);
|
|
assert.strictEqual(normalizeSiteUrl(' '), null);
|
|
assert.strictEqual(normalizeSiteUrl('not a url'), null);
|
|
assert.strictEqual(normalizeSiteUrl(undefined), null);
|
|
});
|
|
|
|
test('labelForUrl derives the hostname', function (assert) {
|
|
assert.strictEqual(
|
|
labelForUrl('https://forum.example.com/latest'),
|
|
'forum.example.com'
|
|
);
|
|
assert.strictEqual(labelForUrl('junk'), 'junk');
|
|
});
|
|
});
|