Skip to content

Commit 4a001fd

Browse files
Resolve Protocol relative URL issue (#2)
1 parent f49b288 commit 4a001fd

File tree

4 files changed

+13
-6
lines changed

4 files changed

+13
-6
lines changed

CHANGELOG.md

+6
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
11
# detect-external-link changelog
22

3+
## 1.0.2 - Aug 25, 2023
4+
5+
### Bug
6+
7+
- Resolve Protocol relative URL issue
8+
39
## 1.0.1 - Jul 26, 2023
410

511
### Enhancement

index.js

+2-2
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,8 @@ function detectExternalLink(linkToCheck, options) {
1919
if (linkToCheck.indexOf('http://') === 0 || linkToCheck.indexOf('https://') === 0) {
2020
linkOrigin = new URL(linkToCheck).hostname;
2121
}
22-
else if (linkToCheck.indexOf('://') === 0) {
23-
linkOrigin = new URL('https' + linkToCheck).hostname;
22+
else if (linkToCheck.indexOf('//') === 0) {
23+
linkOrigin = new URL('https:' + linkToCheck).hostname;
2424
}
2525
if (linkOrigin) {
2626
if (configHosts.length === 0 || configHosts.indexOf(linkOrigin) === -1) {

package.json

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
{
22
"name": "detect-external-link",
33
"description": "Node.js plugin that analyzes the given link and determines if the URL is internal or external.",
4-
"version": "1.0.1",
4+
"version": "1.0.2",
55
"main": "index.js",
66
"types": "types/index.d.ts",
77
"files": [
@@ -24,6 +24,7 @@
2424
"url": "https://github.com/trunkcode/detect-external-link.git"
2525
},
2626
"keywords": [
27+
"detection",
2728
"external-link"
2829
],
2930
"author": "TrunkCode <support@trunkcode.com>",
@@ -40,4 +41,4 @@
4041
"tsd": "0.28.1",
4142
"typescript": "5.1.6"
4243
}
43-
}
44+
}

src/index.ts

+2-2
Original file line numberDiff line numberDiff line change
@@ -20,8 +20,8 @@ export default function detectExternalLink (linkToCheck: string, options: types.
2020

2121
if (linkToCheck.indexOf('http://') === 0 || linkToCheck.indexOf('https://') === 0) {
2222
linkOrigin = new URL(linkToCheck).hostname;
23-
} else if (linkToCheck.indexOf('://') === 0) {
24-
linkOrigin = new URL('https' + linkToCheck).hostname;
23+
} else if (linkToCheck.indexOf('//') === 0) {
24+
linkOrigin = new URL('https:' + linkToCheck).hostname;
2525
}
2626

2727
if (linkOrigin) {

0 commit comments

Comments
 (0)