Skip to content

Commit 477d9be

Browse files
authored
Merge pull request #197 from bobpiece/clickable-relative-paths
adding support for clickable relative paths
2 parents f72ff5f + 624d0cf commit 477d9be

File tree

1 file changed

+18
-20
lines changed

1 file changed

+18
-20
lines changed

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

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -53,23 +53,21 @@
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 relativePath() {
58+
return "(?:[/?#]\\S*)?";
59+
}
60+
61+
function absolutePath() {
62+
return "(?:(?:https?|ftp)://)" + /* protocol identifier*/
63+
"(?:\\S+(?::\\S*)?@)?" + /* user:pass authentication*/
64+
"(?:" +
65+
"(?:\\[[a-f0-9.:]+\\])" + /* IPv6 or hybrid addresses*/
66+
"|" +
67+
"(?:[a-z0-9\\u00a1-\\uffff.-]+)" + /* anything else, including IPv4 addresses */
68+
")" +
69+
"(?::\\d{2,5})?" + /* port number*/
70+
relativePath(); /* resource path*/
71+
}
72+
73+
module.exports = new RegExp(`^(${absolutePath()}|${relativePath()})$`, "i");

0 commit comments

Comments
 (0)