@atlaskit/smart-card 25.5.6 → 25.5.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 +6 -0
- package/dist/cjs/version.json +1 -1
- package/dist/cjs/view/LinkUrl/LinkWarningModal/hooks/use-link-warning-modal.js +26 -3
- package/dist/es2019/version.json +1 -1
- package/dist/es2019/view/LinkUrl/LinkWarningModal/hooks/use-link-warning-modal.js +26 -3
- package/dist/esm/version.json +1 -1
- package/dist/esm/view/LinkUrl/LinkWarningModal/hooks/use-link-warning-modal.js +26 -3
- package/dist/types/view/LinkUrl/LinkWarningModal/hooks/use-link-warning-modal.d.ts +1 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,11 @@
|
|
|
1
1
|
# @atlaskit/smart-card
|
|
2
2
|
|
|
3
|
+
## 25.5.7
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`4c046475c1b`](https://bitbucket.org/atlassian/atlassian-frontend/commits/4c046475c1b) - Fix LinkUrl component: it should not show warning for many cases when it does right now (like relative path comparasion)
|
|
8
|
+
|
|
3
9
|
## 25.5.6
|
|
4
10
|
|
|
5
11
|
### Patch Changes
|
package/dist/cjs/version.json
CHANGED
|
@@ -38,14 +38,37 @@ var useLinkWarningModal = function useLinkWarningModal() {
|
|
|
38
38
|
* It checks and warns if a link text is a URL and different from an actual link destination
|
|
39
39
|
*/
|
|
40
40
|
var checkLinkSafety = function checkLinkSafety(event, href) {
|
|
41
|
-
|
|
41
|
+
if (!href) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
var anchor = event.currentTarget;
|
|
45
|
+
var linkText = anchor.innerText;
|
|
46
|
+
var normalisedUrlFromLinkText = (0, _url.normalizeUrl)(linkText);
|
|
47
|
+
if (!normalisedUrlFromLinkText) {
|
|
48
|
+
return;
|
|
49
|
+
}
|
|
42
50
|
var anchorLinkRegex = new RegExp(/^#/im);
|
|
43
51
|
var isAnchorLink = anchorLinkRegex.test(linkText);
|
|
44
52
|
if (isAnchorLink) {
|
|
45
53
|
return;
|
|
46
54
|
}
|
|
47
|
-
var
|
|
48
|
-
|
|
55
|
+
var relativeLinkRegex = new RegExp(/^\//im);
|
|
56
|
+
var isRelativeHrefLink = relativeLinkRegex.test(href);
|
|
57
|
+
if (isRelativeHrefLink) {
|
|
58
|
+
return;
|
|
59
|
+
}
|
|
60
|
+
var hrefUrl = new URL(href, window.location.origin);
|
|
61
|
+
var linkTextUrl = new URL(normalisedUrlFromLinkText, hrefUrl.origin);
|
|
62
|
+
var httpProtocols = ['http:', 'https:'];
|
|
63
|
+
var areProtocolsEquivalent;
|
|
64
|
+
if (httpProtocols.includes(linkTextUrl.protocol) && httpProtocols.includes(hrefUrl.protocol)) {
|
|
65
|
+
var noUserNameAndPassword = !linkTextUrl.username && !linkTextUrl.password && !hrefUrl.username && !hrefUrl.password;
|
|
66
|
+
areProtocolsEquivalent = noUserNameAndPassword;
|
|
67
|
+
} else {
|
|
68
|
+
areProtocolsEquivalent = linkTextUrl.protocol === hrefUrl.protocol;
|
|
69
|
+
}
|
|
70
|
+
var areEquivalentLinks = linkTextUrl.hostname === hrefUrl.hostname && linkTextUrl.pathname === hrefUrl.pathname && linkTextUrl.search === hrefUrl.search && linkTextUrl.username === hrefUrl.username && linkTextUrl.password === hrefUrl.password && areProtocolsEquivalent;
|
|
71
|
+
if (!areEquivalentLinks) {
|
|
49
72
|
event.preventDefault();
|
|
50
73
|
setUnsafeLinkText(linkText);
|
|
51
74
|
href && setUrl(href);
|
package/dist/es2019/version.json
CHANGED
|
@@ -22,14 +22,37 @@ export const useLinkWarningModal = () => {
|
|
|
22
22
|
* It checks and warns if a link text is a URL and different from an actual link destination
|
|
23
23
|
*/
|
|
24
24
|
const checkLinkSafety = (event, href) => {
|
|
25
|
-
|
|
25
|
+
if (!href) {
|
|
26
|
+
return;
|
|
27
|
+
}
|
|
28
|
+
const anchor = event.currentTarget;
|
|
29
|
+
const linkText = anchor.innerText;
|
|
30
|
+
const normalisedUrlFromLinkText = normalizeUrl(linkText);
|
|
31
|
+
if (!normalisedUrlFromLinkText) {
|
|
32
|
+
return;
|
|
33
|
+
}
|
|
26
34
|
const anchorLinkRegex = new RegExp(/^#/im);
|
|
27
35
|
const isAnchorLink = anchorLinkRegex.test(linkText);
|
|
28
36
|
if (isAnchorLink) {
|
|
29
37
|
return;
|
|
30
38
|
}
|
|
31
|
-
const
|
|
32
|
-
|
|
39
|
+
const relativeLinkRegex = new RegExp(/^\//im);
|
|
40
|
+
const isRelativeHrefLink = relativeLinkRegex.test(href);
|
|
41
|
+
if (isRelativeHrefLink) {
|
|
42
|
+
return;
|
|
43
|
+
}
|
|
44
|
+
const hrefUrl = new URL(href, window.location.origin);
|
|
45
|
+
const linkTextUrl = new URL(normalisedUrlFromLinkText, hrefUrl.origin);
|
|
46
|
+
const httpProtocols = ['http:', 'https:'];
|
|
47
|
+
let areProtocolsEquivalent;
|
|
48
|
+
if (httpProtocols.includes(linkTextUrl.protocol) && httpProtocols.includes(hrefUrl.protocol)) {
|
|
49
|
+
const noUserNameAndPassword = !linkTextUrl.username && !linkTextUrl.password && !hrefUrl.username && !hrefUrl.password;
|
|
50
|
+
areProtocolsEquivalent = noUserNameAndPassword;
|
|
51
|
+
} else {
|
|
52
|
+
areProtocolsEquivalent = linkTextUrl.protocol === hrefUrl.protocol;
|
|
53
|
+
}
|
|
54
|
+
const areEquivalentLinks = linkTextUrl.hostname === hrefUrl.hostname && linkTextUrl.pathname === hrefUrl.pathname && linkTextUrl.search === hrefUrl.search && linkTextUrl.username === hrefUrl.username && linkTextUrl.password === hrefUrl.password && areProtocolsEquivalent;
|
|
55
|
+
if (!areEquivalentLinks) {
|
|
33
56
|
event.preventDefault();
|
|
34
57
|
setUnsafeLinkText(linkText);
|
|
35
58
|
href && setUrl(href);
|
package/dist/esm/version.json
CHANGED
|
@@ -31,14 +31,37 @@ export var useLinkWarningModal = function useLinkWarningModal() {
|
|
|
31
31
|
* It checks and warns if a link text is a URL and different from an actual link destination
|
|
32
32
|
*/
|
|
33
33
|
var checkLinkSafety = function checkLinkSafety(event, href) {
|
|
34
|
-
|
|
34
|
+
if (!href) {
|
|
35
|
+
return;
|
|
36
|
+
}
|
|
37
|
+
var anchor = event.currentTarget;
|
|
38
|
+
var linkText = anchor.innerText;
|
|
39
|
+
var normalisedUrlFromLinkText = normalizeUrl(linkText);
|
|
40
|
+
if (!normalisedUrlFromLinkText) {
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
35
43
|
var anchorLinkRegex = new RegExp(/^#/im);
|
|
36
44
|
var isAnchorLink = anchorLinkRegex.test(linkText);
|
|
37
45
|
if (isAnchorLink) {
|
|
38
46
|
return;
|
|
39
47
|
}
|
|
40
|
-
var
|
|
41
|
-
|
|
48
|
+
var relativeLinkRegex = new RegExp(/^\//im);
|
|
49
|
+
var isRelativeHrefLink = relativeLinkRegex.test(href);
|
|
50
|
+
if (isRelativeHrefLink) {
|
|
51
|
+
return;
|
|
52
|
+
}
|
|
53
|
+
var hrefUrl = new URL(href, window.location.origin);
|
|
54
|
+
var linkTextUrl = new URL(normalisedUrlFromLinkText, hrefUrl.origin);
|
|
55
|
+
var httpProtocols = ['http:', 'https:'];
|
|
56
|
+
var areProtocolsEquivalent;
|
|
57
|
+
if (httpProtocols.includes(linkTextUrl.protocol) && httpProtocols.includes(hrefUrl.protocol)) {
|
|
58
|
+
var noUserNameAndPassword = !linkTextUrl.username && !linkTextUrl.password && !hrefUrl.username && !hrefUrl.password;
|
|
59
|
+
areProtocolsEquivalent = noUserNameAndPassword;
|
|
60
|
+
} else {
|
|
61
|
+
areProtocolsEquivalent = linkTextUrl.protocol === hrefUrl.protocol;
|
|
62
|
+
}
|
|
63
|
+
var areEquivalentLinks = linkTextUrl.hostname === hrefUrl.hostname && linkTextUrl.pathname === hrefUrl.pathname && linkTextUrl.search === hrefUrl.search && linkTextUrl.username === hrefUrl.username && linkTextUrl.password === hrefUrl.password && areProtocolsEquivalent;
|
|
64
|
+
if (!areEquivalentLinks) {
|
|
42
65
|
event.preventDefault();
|
|
43
66
|
setUnsafeLinkText(linkText);
|
|
44
67
|
href && setUrl(href);
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import { MouseEvent } from 'react';
|
|
2
2
|
export declare const useLinkWarningModal: () => {
|
|
3
|
-
checkLinkSafety: (event: MouseEvent
|
|
3
|
+
checkLinkSafety: (event: MouseEvent<HTMLAnchorElement>, href: string | undefined) => void;
|
|
4
4
|
unsafeLinkText: string | null;
|
|
5
5
|
onClose: () => void;
|
|
6
6
|
onContinue: () => void;
|