@atlaskit/link-picker 1.16.6 → 1.16.7
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +7 -0
- package/dist/cjs/common/analytics/context.js +1 -1
- package/dist/cjs/services/use-search-query/index.js +1 -1
- package/dist/cjs/ui/link-picker/form-footer/utils.js +1 -1
- package/dist/cjs/ui/link-picker/index.js +1 -1
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/common/analytics/context.js +1 -1
- package/dist/es2019/services/use-search-query/index.js +1 -1
- package/dist/es2019/ui/link-picker/form-footer/utils.js +1 -1
- package/dist/es2019/ui/link-picker/index.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/esm/common/analytics/context.js +1 -1
- package/dist/esm/services/use-search-query/index.js +1 -1
- package/dist/esm/ui/link-picker/form-footer/utils.js +1 -1
- package/dist/esm/ui/link-picker/index.js +1 -1
- package/dist/esm/version.json +1 -1
- package/package.json +2 -2
- package/dist/cjs/common/utils/url.js +0 -104
- package/dist/es2019/common/utils/url.js +0 -88
- package/dist/esm/common/utils/url.js +0 -90
- package/dist/types/common/utils/url.d.ts +0 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,12 @@
|
|
|
1
1
|
# @atlaskit/link-picker
|
|
2
2
|
|
|
3
|
+
## 1.16.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`10410539ac9`](https://bitbucket.org/atlassian/atlassian-frontend/commits/10410539ac9) - Url utils added (normalizeURL and isSafeUrl). Available to export
|
|
8
|
+
- Updated dependencies
|
|
9
|
+
|
|
3
10
|
## 1.16.6
|
|
4
11
|
|
|
5
12
|
### Patch Changes
|
|
@@ -22,7 +22,7 @@ var _analyticsNext = require("@atlaskit/analytics-next");
|
|
|
22
22
|
|
|
23
23
|
var _constants = require("../constants");
|
|
24
24
|
|
|
25
|
-
var _url = require("
|
|
25
|
+
var _url = require("@atlaskit/linking-common/url");
|
|
26
26
|
|
|
27
27
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
28
28
|
|
|
@@ -5,7 +5,7 @@ Object.defineProperty(exports, "__esModule", {
|
|
|
5
5
|
});
|
|
6
6
|
exports.checkSubmitDisabled = void 0;
|
|
7
7
|
|
|
8
|
-
var _url = require("
|
|
8
|
+
var _url = require("@atlaskit/linking-common/url");
|
|
9
9
|
|
|
10
10
|
var checkSubmitDisabled = function checkSubmitDisabled(isLoading, error, state, items) {
|
|
11
11
|
/*
|
|
@@ -37,7 +37,7 @@ var _constants = require("../../common/constants");
|
|
|
37
37
|
|
|
38
38
|
var _analytics2 = require("../../common/analytics");
|
|
39
39
|
|
|
40
|
-
var _url2 = require("
|
|
40
|
+
var _url2 = require("@atlaskit/linking-common/url");
|
|
41
41
|
|
|
42
42
|
var _usePlugins2 = require("../../services/use-plugins");
|
|
43
43
|
|
package/dist/cjs/version.json
CHANGED
|
@@ -2,7 +2,7 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
|
2
2
|
import React, { useCallback, useContext, useMemo, useRef, useState } from 'react';
|
|
3
3
|
import { AnalyticsListener } from '@atlaskit/analytics-next';
|
|
4
4
|
import { ANALYTICS_CHANNEL } from '../constants';
|
|
5
|
-
import { normalizeUrl } from '
|
|
5
|
+
import { normalizeUrl } from '@atlaskit/linking-common/url';
|
|
6
6
|
const DEFAULT_CONTEXT_ATTRIBUTES = {
|
|
7
7
|
linkState: 'newLink',
|
|
8
8
|
linkFieldContent: null,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { normalizeUrl } from '
|
|
1
|
+
import { normalizeUrl } from '@atlaskit/linking-common/url';
|
|
2
2
|
export const checkSubmitDisabled = (isLoading, error, state, items) => {
|
|
3
3
|
/*
|
|
4
4
|
* Enable insert when search term is a valid url and it can be normalized
|
|
@@ -11,7 +11,7 @@ import VisuallyHidden from '@atlaskit/visually-hidden';
|
|
|
11
11
|
import createEventPayload from '../../analytics.codegen';
|
|
12
12
|
import { ANALYTICS_CHANNEL } from '../../common/constants';
|
|
13
13
|
import { useLinkPickerAnalytics, withInputFieldTracking, withLinkPickerAnalyticsContext } from '../../common/analytics';
|
|
14
|
-
import { normalizeUrl, isSafeUrl } from '
|
|
14
|
+
import { normalizeUrl, isSafeUrl } from '@atlaskit/linking-common/url';
|
|
15
15
|
import { usePlugins } from '../../services/use-plugins';
|
|
16
16
|
import { useSearchQuery } from '../../services/use-search-query';
|
|
17
17
|
import useFixHeight from '../../controllers/use-fix-height';
|
package/dist/es2019/version.json
CHANGED
|
@@ -9,7 +9,7 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
|
|
|
9
9
|
import React, { useCallback, useContext, useMemo, useRef, useState } from 'react';
|
|
10
10
|
import { AnalyticsListener } from '@atlaskit/analytics-next';
|
|
11
11
|
import { ANALYTICS_CHANNEL } from '../constants';
|
|
12
|
-
import { normalizeUrl } from '
|
|
12
|
+
import { normalizeUrl } from '@atlaskit/linking-common/url';
|
|
13
13
|
var DEFAULT_CONTEXT_ATTRIBUTES = {
|
|
14
14
|
linkState: 'newLink',
|
|
15
15
|
linkFieldContent: null,
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { normalizeUrl } from '
|
|
1
|
+
import { normalizeUrl } from '@atlaskit/linking-common/url';
|
|
2
2
|
export var checkSubmitDisabled = function checkSubmitDisabled(isLoading, error, state, items) {
|
|
3
3
|
/*
|
|
4
4
|
* Enable insert when search term is a valid url and it can be normalized
|
|
@@ -19,7 +19,7 @@ import VisuallyHidden from '@atlaskit/visually-hidden';
|
|
|
19
19
|
import createEventPayload from '../../analytics.codegen';
|
|
20
20
|
import { ANALYTICS_CHANNEL } from '../../common/constants';
|
|
21
21
|
import { useLinkPickerAnalytics, withInputFieldTracking, withLinkPickerAnalyticsContext } from '../../common/analytics';
|
|
22
|
-
import { normalizeUrl, isSafeUrl } from '
|
|
22
|
+
import { normalizeUrl, isSafeUrl } from '@atlaskit/linking-common/url';
|
|
23
23
|
import { usePlugins } from '../../services/use-plugins';
|
|
24
24
|
import { useSearchQuery } from '../../services/use-search-query';
|
|
25
25
|
import useFixHeight from '../../controllers/use-fix-height';
|
package/dist/esm/version.json
CHANGED
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/link-picker",
|
|
3
|
-
"version": "1.16.
|
|
3
|
+
"version": "1.16.7",
|
|
4
4
|
"description": "Standalone link picker",
|
|
5
5
|
"author": "Atlassian Pty Ltd",
|
|
6
6
|
"publishConfig": {
|
|
@@ -37,6 +37,7 @@
|
|
|
37
37
|
"@atlaskit/form": "^8.8.0",
|
|
38
38
|
"@atlaskit/frontend-utilities": "^2.1.0",
|
|
39
39
|
"@atlaskit/icon": "^21.11.0",
|
|
40
|
+
"@atlaskit/linking-common": "^1.17.0",
|
|
40
41
|
"@atlaskit/spinner": "^15.3.0",
|
|
41
42
|
"@atlaskit/tabs": "^13.3.0",
|
|
42
43
|
"@atlaskit/textfield": "^5.3.0",
|
|
@@ -49,7 +50,6 @@
|
|
|
49
50
|
"@emotion/react": "^11.7.1",
|
|
50
51
|
"@react-loosely-lazy/manifest": "^1.0.0",
|
|
51
52
|
"date-fns": "^2.17.0",
|
|
52
|
-
"linkify-it": "^2.0.3",
|
|
53
53
|
"react-loosely-lazy": "^1.0.0",
|
|
54
54
|
"use-debounce": "^3.4.0",
|
|
55
55
|
"uuid": "^3.1.0"
|
|
@@ -1,104 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
|
|
3
|
-
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
-
|
|
5
|
-
Object.defineProperty(exports, "__esModule", {
|
|
6
|
-
value: true
|
|
7
|
-
});
|
|
8
|
-
exports.isSafeUrl = void 0;
|
|
9
|
-
exports.normalizeUrl = normalizeUrl;
|
|
10
|
-
|
|
11
|
-
var _linkifyIt = _interopRequireDefault(require("linkify-it"));
|
|
12
|
-
|
|
13
|
-
/**
|
|
14
|
-
* This file has been duplicated in packages/editor/adf-schema/src/utils/url.ts
|
|
15
|
-
* Any changes made here should be mirrored there.
|
|
16
|
-
*/
|
|
17
|
-
var linkify = (0, _linkifyIt.default)();
|
|
18
|
-
linkify.add('sourcetree:', 'http:');
|
|
19
|
-
linkify.add('jamfselfservice:', 'http:');
|
|
20
|
-
var tlds = 'biz|com|edu|gov|net|org|pro|web|xxx|aero|asia|coop|info|museum|name|shop|рф'.split('|');
|
|
21
|
-
var tlds2Char = 'a[cdefgilmnoqrtuwxz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvwxyz]|d[ejkmoz]|e[cegrstu]|f[ijkmor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdeghklmnopqrtuvwxyz]|n[acefgilopruz]|om|p[aefghkmnrtw]|qa|r[eosuw]|s[abcdegijklmnrtuvxyz]|t[cdfghjklmnortvwz]|u[agksyz]|v[aceginu]|w[fs]|y[et]|z[amw]';
|
|
22
|
-
tlds.push(tlds2Char);
|
|
23
|
-
linkify.tlds(tlds, false);
|
|
24
|
-
var whitelistedURLPatterns = [/^https?:\/\/[^\s]*$/im, /^ftps?:\/\//im, /^jamfselfservice:\/\/[^\s]*$/im, /^\//im, /^mailto:/im, /^skype:/im, /^callto:[^\s]*$/im, /^facetime:[^\s]*$/im, /^git:/im, /^irc6?:/im, /^news:/im, /^nntp:/im, /^feed:/im, /^cvs:/im, /^svn:/im, /^mvn:/im, /^ssh:/im, /^scp:\/\//im, /^sftp:\/\//im, /^itms:/im, /^notes:/im, /^hipchat:\/\//im, /^sourcetree:/im, /^urn:/im, /^tel:/im, /^xmpp:/im, /^telnet:/im, /^vnc:/im, /^rdp:/im, /^whatsapp:/im, /^slack:/im, /^sips?:/im, /^magnet:/im, /^foo:/im, /^#/im];
|
|
25
|
-
|
|
26
|
-
var normaliseLinkHref = function normaliseLinkHref(url) {
|
|
27
|
-
var match = getLinkMatch(url);
|
|
28
|
-
return match && match.url || null;
|
|
29
|
-
};
|
|
30
|
-
|
|
31
|
-
var getLinkMatch = function getLinkMatch(str) {
|
|
32
|
-
if (!str) {
|
|
33
|
-
return null;
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
var match = linkifyMatch(str);
|
|
37
|
-
|
|
38
|
-
if (!match.length) {
|
|
39
|
-
match = linkify.match(str);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
return match && match.length > 0 && match[0].index === 0 && match[0].lastIndex === str.trim().length ? match[0] : null;
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
var LINK_REGEXP = /(https?|ftp|jamfselfservice):\/\/[^\s]+/;
|
|
46
|
-
|
|
47
|
-
var linkifyMatch = function linkifyMatch(text) {
|
|
48
|
-
var matches = [];
|
|
49
|
-
|
|
50
|
-
if (!LINK_REGEXP.test(text)) {
|
|
51
|
-
return matches;
|
|
52
|
-
}
|
|
53
|
-
|
|
54
|
-
var startpos = 0;
|
|
55
|
-
var substr;
|
|
56
|
-
|
|
57
|
-
while (substr = text.substr(startpos)) {
|
|
58
|
-
var link = (substr.match(LINK_REGEXP) || [''])[0];
|
|
59
|
-
|
|
60
|
-
if (link) {
|
|
61
|
-
var index = substr.search(LINK_REGEXP);
|
|
62
|
-
var start = index >= 0 ? index + startpos : index;
|
|
63
|
-
var end = start + link.length;
|
|
64
|
-
matches.push({
|
|
65
|
-
index: start,
|
|
66
|
-
lastIndex: end,
|
|
67
|
-
raw: link,
|
|
68
|
-
url: link,
|
|
69
|
-
text: link,
|
|
70
|
-
schema: ''
|
|
71
|
-
});
|
|
72
|
-
startpos += end;
|
|
73
|
-
} else {
|
|
74
|
-
break;
|
|
75
|
-
}
|
|
76
|
-
}
|
|
77
|
-
|
|
78
|
-
return matches;
|
|
79
|
-
};
|
|
80
|
-
|
|
81
|
-
var isSafeUrl = function isSafeUrl(url) {
|
|
82
|
-
var urlTrimmed = url.trim();
|
|
83
|
-
return whitelistedURLPatterns.some(function (p) {
|
|
84
|
-
return p.test(urlTrimmed);
|
|
85
|
-
});
|
|
86
|
-
};
|
|
87
|
-
/**
|
|
88
|
-
* Adds protocol to url if needed.
|
|
89
|
-
*/
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
exports.isSafeUrl = isSafeUrl;
|
|
93
|
-
|
|
94
|
-
function normalizeUrl(url) {
|
|
95
|
-
if (!url) {
|
|
96
|
-
return '';
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
if (isSafeUrl(url)) {
|
|
100
|
-
return url.trim();
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
return normaliseLinkHref(url);
|
|
104
|
-
}
|
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file has been duplicated in packages/editor/adf-schema/src/utils/url.ts
|
|
3
|
-
* Any changes made here should be mirrored there.
|
|
4
|
-
*/
|
|
5
|
-
import LinkifyIt from 'linkify-it';
|
|
6
|
-
const linkify = LinkifyIt();
|
|
7
|
-
linkify.add('sourcetree:', 'http:');
|
|
8
|
-
linkify.add('jamfselfservice:', 'http:');
|
|
9
|
-
const tlds = 'biz|com|edu|gov|net|org|pro|web|xxx|aero|asia|coop|info|museum|name|shop|рф'.split('|');
|
|
10
|
-
const tlds2Char = 'a[cdefgilmnoqrtuwxz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvwxyz]|d[ejkmoz]|e[cegrstu]|f[ijkmor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdeghklmnopqrtuvwxyz]|n[acefgilopruz]|om|p[aefghkmnrtw]|qa|r[eosuw]|s[abcdegijklmnrtuvxyz]|t[cdfghjklmnortvwz]|u[agksyz]|v[aceginu]|w[fs]|y[et]|z[amw]';
|
|
11
|
-
tlds.push(tlds2Char);
|
|
12
|
-
linkify.tlds(tlds, false);
|
|
13
|
-
const whitelistedURLPatterns = [/^https?:\/\/[^\s]*$/im, /^ftps?:\/\//im, /^jamfselfservice:\/\/[^\s]*$/im, /^\//im, /^mailto:/im, /^skype:/im, /^callto:[^\s]*$/im, /^facetime:[^\s]*$/im, /^git:/im, /^irc6?:/im, /^news:/im, /^nntp:/im, /^feed:/im, /^cvs:/im, /^svn:/im, /^mvn:/im, /^ssh:/im, /^scp:\/\//im, /^sftp:\/\//im, /^itms:/im, /^notes:/im, /^hipchat:\/\//im, /^sourcetree:/im, /^urn:/im, /^tel:/im, /^xmpp:/im, /^telnet:/im, /^vnc:/im, /^rdp:/im, /^whatsapp:/im, /^slack:/im, /^sips?:/im, /^magnet:/im, /^foo:/im, /^#/im];
|
|
14
|
-
|
|
15
|
-
const normaliseLinkHref = url => {
|
|
16
|
-
const match = getLinkMatch(url);
|
|
17
|
-
return match && match.url || null;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
const getLinkMatch = str => {
|
|
21
|
-
if (!str) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
let match = linkifyMatch(str);
|
|
26
|
-
|
|
27
|
-
if (!match.length) {
|
|
28
|
-
match = linkify.match(str);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return match && match.length > 0 && match[0].index === 0 && match[0].lastIndex === str.trim().length ? match[0] : null;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
const LINK_REGEXP = /(https?|ftp|jamfselfservice):\/\/[^\s]+/;
|
|
35
|
-
|
|
36
|
-
const linkifyMatch = text => {
|
|
37
|
-
const matches = [];
|
|
38
|
-
|
|
39
|
-
if (!LINK_REGEXP.test(text)) {
|
|
40
|
-
return matches;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
let startpos = 0;
|
|
44
|
-
let substr;
|
|
45
|
-
|
|
46
|
-
while (substr = text.substr(startpos)) {
|
|
47
|
-
const link = (substr.match(LINK_REGEXP) || [''])[0];
|
|
48
|
-
|
|
49
|
-
if (link) {
|
|
50
|
-
const index = substr.search(LINK_REGEXP);
|
|
51
|
-
const start = index >= 0 ? index + startpos : index;
|
|
52
|
-
const end = start + link.length;
|
|
53
|
-
matches.push({
|
|
54
|
-
index: start,
|
|
55
|
-
lastIndex: end,
|
|
56
|
-
raw: link,
|
|
57
|
-
url: link,
|
|
58
|
-
text: link,
|
|
59
|
-
schema: ''
|
|
60
|
-
});
|
|
61
|
-
startpos += end;
|
|
62
|
-
} else {
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return matches;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export const isSafeUrl = url => {
|
|
71
|
-
const urlTrimmed = url.trim();
|
|
72
|
-
return whitelistedURLPatterns.some(p => p.test(urlTrimmed));
|
|
73
|
-
};
|
|
74
|
-
/**
|
|
75
|
-
* Adds protocol to url if needed.
|
|
76
|
-
*/
|
|
77
|
-
|
|
78
|
-
export function normalizeUrl(url) {
|
|
79
|
-
if (!url) {
|
|
80
|
-
return '';
|
|
81
|
-
}
|
|
82
|
-
|
|
83
|
-
if (isSafeUrl(url)) {
|
|
84
|
-
return url.trim();
|
|
85
|
-
}
|
|
86
|
-
|
|
87
|
-
return normaliseLinkHref(url);
|
|
88
|
-
}
|
|
@@ -1,90 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* This file has been duplicated in packages/editor/adf-schema/src/utils/url.ts
|
|
3
|
-
* Any changes made here should be mirrored there.
|
|
4
|
-
*/
|
|
5
|
-
import LinkifyIt from 'linkify-it';
|
|
6
|
-
var linkify = LinkifyIt();
|
|
7
|
-
linkify.add('sourcetree:', 'http:');
|
|
8
|
-
linkify.add('jamfselfservice:', 'http:');
|
|
9
|
-
var tlds = 'biz|com|edu|gov|net|org|pro|web|xxx|aero|asia|coop|info|museum|name|shop|рф'.split('|');
|
|
10
|
-
var tlds2Char = 'a[cdefgilmnoqrtuwxz]|b[abdefghijmnorstvwyz]|c[acdfghiklmnoruvwxyz]|d[ejkmoz]|e[cegrstu]|f[ijkmor]|g[abdefghilmnpqrstuwy]|h[kmnrtu]|i[delmnoqrst]|j[emop]|k[eghimnprwyz]|l[abcikrstuvy]|m[acdeghklmnopqrtuvwxyz]|n[acefgilopruz]|om|p[aefghkmnrtw]|qa|r[eosuw]|s[abcdegijklmnrtuvxyz]|t[cdfghjklmnortvwz]|u[agksyz]|v[aceginu]|w[fs]|y[et]|z[amw]';
|
|
11
|
-
tlds.push(tlds2Char);
|
|
12
|
-
linkify.tlds(tlds, false);
|
|
13
|
-
var whitelistedURLPatterns = [/^https?:\/\/[^\s]*$/im, /^ftps?:\/\//im, /^jamfselfservice:\/\/[^\s]*$/im, /^\//im, /^mailto:/im, /^skype:/im, /^callto:[^\s]*$/im, /^facetime:[^\s]*$/im, /^git:/im, /^irc6?:/im, /^news:/im, /^nntp:/im, /^feed:/im, /^cvs:/im, /^svn:/im, /^mvn:/im, /^ssh:/im, /^scp:\/\//im, /^sftp:\/\//im, /^itms:/im, /^notes:/im, /^hipchat:\/\//im, /^sourcetree:/im, /^urn:/im, /^tel:/im, /^xmpp:/im, /^telnet:/im, /^vnc:/im, /^rdp:/im, /^whatsapp:/im, /^slack:/im, /^sips?:/im, /^magnet:/im, /^foo:/im, /^#/im];
|
|
14
|
-
|
|
15
|
-
var normaliseLinkHref = function normaliseLinkHref(url) {
|
|
16
|
-
var match = getLinkMatch(url);
|
|
17
|
-
return match && match.url || null;
|
|
18
|
-
};
|
|
19
|
-
|
|
20
|
-
var getLinkMatch = function getLinkMatch(str) {
|
|
21
|
-
if (!str) {
|
|
22
|
-
return null;
|
|
23
|
-
}
|
|
24
|
-
|
|
25
|
-
var match = linkifyMatch(str);
|
|
26
|
-
|
|
27
|
-
if (!match.length) {
|
|
28
|
-
match = linkify.match(str);
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
return match && match.length > 0 && match[0].index === 0 && match[0].lastIndex === str.trim().length ? match[0] : null;
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
var LINK_REGEXP = /(https?|ftp|jamfselfservice):\/\/[^\s]+/;
|
|
35
|
-
|
|
36
|
-
var linkifyMatch = function linkifyMatch(text) {
|
|
37
|
-
var matches = [];
|
|
38
|
-
|
|
39
|
-
if (!LINK_REGEXP.test(text)) {
|
|
40
|
-
return matches;
|
|
41
|
-
}
|
|
42
|
-
|
|
43
|
-
var startpos = 0;
|
|
44
|
-
var substr;
|
|
45
|
-
|
|
46
|
-
while (substr = text.substr(startpos)) {
|
|
47
|
-
var link = (substr.match(LINK_REGEXP) || [''])[0];
|
|
48
|
-
|
|
49
|
-
if (link) {
|
|
50
|
-
var index = substr.search(LINK_REGEXP);
|
|
51
|
-
var start = index >= 0 ? index + startpos : index;
|
|
52
|
-
var end = start + link.length;
|
|
53
|
-
matches.push({
|
|
54
|
-
index: start,
|
|
55
|
-
lastIndex: end,
|
|
56
|
-
raw: link,
|
|
57
|
-
url: link,
|
|
58
|
-
text: link,
|
|
59
|
-
schema: ''
|
|
60
|
-
});
|
|
61
|
-
startpos += end;
|
|
62
|
-
} else {
|
|
63
|
-
break;
|
|
64
|
-
}
|
|
65
|
-
}
|
|
66
|
-
|
|
67
|
-
return matches;
|
|
68
|
-
};
|
|
69
|
-
|
|
70
|
-
export var isSafeUrl = function isSafeUrl(url) {
|
|
71
|
-
var urlTrimmed = url.trim();
|
|
72
|
-
return whitelistedURLPatterns.some(function (p) {
|
|
73
|
-
return p.test(urlTrimmed);
|
|
74
|
-
});
|
|
75
|
-
};
|
|
76
|
-
/**
|
|
77
|
-
* Adds protocol to url if needed.
|
|
78
|
-
*/
|
|
79
|
-
|
|
80
|
-
export function normalizeUrl(url) {
|
|
81
|
-
if (!url) {
|
|
82
|
-
return '';
|
|
83
|
-
}
|
|
84
|
-
|
|
85
|
-
if (isSafeUrl(url)) {
|
|
86
|
-
return url.trim();
|
|
87
|
-
}
|
|
88
|
-
|
|
89
|
-
return normaliseLinkHref(url);
|
|
90
|
-
}
|