Skip to content

Commit 5dd952b

Browse files
committed
adding support for clickable relative paths
1 parent f63c6aa commit 5dd952b

File tree

1 file changed

+26
-20
lines changed

1 file changed

+26
-20
lines changed

extension/src/json-viewer/url-pattern.js

Lines changed: 26 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,29 @@
5353
// - Made starting path slash optional (http://example.com?foo=bar)
5454
//
5555
// - Allow a dot (.) at the end of hostnames (http://example.com.)
56-
//
57-
module.exports = new RegExp(
58-
"^" +
59-
// protocol identifier
60-
"(?:(?:https?|ftp)://)" +
61-
// user:pass authentication
62-
"(?:\\S+(?::\\S*)?@)?" +
63-
"(?:" +
64-
// IPv6 or hybrid addresses
65-
"(?:\\[[a-f0-9.:]+\\])" +
66-
"|" +
67-
// anything else, including IPv4 addresses
68-
"(?:[a-z0-9\\u00a1-\\uffff.-]+)" +
69-
")" +
70-
// port number
71-
"(?::\\d{2,5})?" +
72-
// resource path
73-
"(?:[/?#]\\S*)?" +
74-
"$", "i"
75-
);
56+
57+
function resourcePath() {
58+
return "(?:[/?#]\\S*)?";
59+
}
60+
61+
function absolutePath() {
62+
return "^" +
63+
// protocol identifier
64+
"(?:(?:https?|ftp)://)" +
65+
// user:pass authentication
66+
"(?:\\S+(?::\\S*)?@)?" +
67+
"(?:" +
68+
// IPv6 or hybrid addresses
69+
"(?:\\[[a-f0-9.:]+\\])" +
70+
"|" +
71+
// anything else, including IPv4 addresses
72+
"(?:[a-z0-9\\u00a1-\\uffff.-]+)" +
73+
")" +
74+
// port number
75+
"(?::\\d{2,5})?" +
76+
// resource path
77+
resourcePath() +
78+
"$";
79+
}
80+
81+
module.exports = new RegExp(`${absolutePath()}|${resourcePath()}`, "i");

0 commit comments

Comments
 (0)