diff --git a/dist/index.js b/dist/index.js index 111a11a..ae0dca5 100755 --- a/dist/index.js +++ b/dist/index.js @@ -288,8 +288,7 @@ function normalizeUrl(urlString, options) { const parseUrl = (url, normalize = false) => { // Constants - const GIT_RE = /^(?:([a-z_][a-z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/; - + const GIT_RE = /^(?:([a-z_][a-z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:](([\~,\.\w,\-,\_,\/,\s]|%[0-9A-Fa-f]{2})+?(?:\.git|\/)?)$/; const throwErr = msg => { const err = new Error(msg); err.subject_url = url; diff --git a/dist/index.mjs b/dist/index.mjs index 4fd7be5..40aee2e 100755 --- a/dist/index.mjs +++ b/dist/index.mjs @@ -282,8 +282,7 @@ function normalizeUrl(urlString, options) { const parseUrl = (url, normalize = false) => { // Constants - const GIT_RE = /^(?:([a-z_][a-z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/; - + const GIT_RE = /^(?:([a-z_][a-z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:](([\~,\.\w,\-,\_,\/,\s]|%[0-9A-Fa-f]{2})+?(?:\.git|\/)?)$/; const throwErr = msg => { const err = new Error(msg); err.subject_url = url; diff --git a/package.json b/package.json index 9418eb4..3d6579c 100644 --- a/package.json +++ b/package.json @@ -6,12 +6,14 @@ "module": "./dist/index.mjs", "types": "./index.d.ts", "exports": { - "types": { - "require": "./index.d.ts", - "import": "./index.d.mts" + "require": { + "types": "./index.d.ts", + "default": "./dist/index.js" }, - "require": "./dist/index.js", - "import": "./dist/index.mjs" + "import": { + "types": "./index.d.mts", + "default": "./dist/index.mjs" + } }, "directories": { "example": "example", diff --git a/src/index.js b/src/index.js index b165cc7..adab6c4 100644 --- a/src/index.js +++ b/src/index.js @@ -1,6 +1,7 @@ // Dependencies -import parsePath from "parse-path"; + import normalizeUrl from "normalize-url"; +import parsePath from "parse-path"; /** * parseUrl @@ -35,8 +36,13 @@ import normalizeUrl from "normalize-url"; const parseUrl = (url, normalize = false) => { // Constants - const GIT_RE = /^(?:([a-z_][a-z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/ - + /** + * ([a-z_][a-z0-9_-]{0,31}) Try to match the user + * ([\w\.\-@]+) Match the host/resource + * (([\~,\.\w,\-,\_,\/,\s]|%[0-9A-Fa-f]{2})+?(?:\.git|\/)?) Match the path, allowing spaces/white + */ + const GIT_RE = /^(?:([a-z_][a-z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:](([\~,\.\w,\-,\_,\/,\s]|%[0-9A-Fa-f]{2})+?(?:\.git|\/)?)$/; + const throwErr = msg => { const err = new Error(msg) err.subject_url = url @@ -84,4 +90,4 @@ const parseUrl = (url, normalize = false) => { parseUrl.MAX_INPUT_LENGTH = 2048 -export default parseUrl; +export default parseUrl; \ No newline at end of file diff --git a/test/index.mjs b/test/index.mjs index 90b04b0..ca99728 100644 --- a/test/index.mjs +++ b/test/index.mjs @@ -1,7 +1,8 @@ // Dependencies + +import normalizeUrl from "normalize-url"; import parseUrl from "../dist/index.js"; import tester from "tester"; -import normalizeUrl from "normalize-url"; const INPUTS = [ [ @@ -165,7 +166,127 @@ const INPUTS = [ , query: {} , parse_failed: false } - ] + ], + [ + [ + "git@ssh.dev.azure.com:v3/ORG/My-Project/repo", + false, + ], + { + protocols: ["ssh"], + protocol: "ssh", + port: "", + resource: "ssh.dev.azure.com", + host: "ssh.dev.azure.com", + user: "git", + password: "", + pathname: "/v3/ORG/My-Project/repo", + hash: "", + search: "", + query: {}, + parse_failed: false, + }, + ], + [ + [ + "git@ssh.dev.azure.com:v3/ORG/My%20Project/repo", + false, + ], + { + protocols: ["ssh"], + protocol: "ssh", + port: "", + resource: "ssh.dev.azure.com", + host: "ssh.dev.azure.com", + user: "git", + password: "", + pathname: "/v3/ORG/My%20Project/repo", + hash: "", + search: "", + query: {}, + parse_failed: false, + }, + ], + [ + [ + "git@ssh.dev.azure.com:v3/ORG/My Project/repo", + false, + ], + { + protocols: ["ssh"], + protocol: "ssh", + port: "", + resource: "ssh.dev.azure.com", + host: "ssh.dev.azure.com", + user: "git", + password: "", + pathname: "/v3/ORG/My Project/repo", + hash: "", + search: "", + query: {}, + parse_failed: false, + }, + ], + [ + [ + "git@ssh.dev.azure.com:v3/ORG/My-Project/repo", + false, + ], + { + protocols: ["ssh"], + protocol: "ssh", + port: "", + resource: "ssh.dev.azure.com", + host: "ssh.dev.azure.com", + user: "git", + password: "", + pathname: "/v3/ORG/My-Project/repo", + hash: "", + search: "", + query: {}, + parse_failed: false, + }, + ], + [ + [ + "https://ORG@dev.azure.com/ORG/My%20Project/_git/repo", + false, + ], + { + protocols: ["https"], + protocol: "https", + port: "", + resource: "dev.azure.com", + host: "dev.azure.com", + user: "ORG", + password: "", + pathname: "/ORG/My%20Project/_git/repo", + hash: "", + search: "", + query: {}, + parse_failed: false, + }, + ], + [ + [ + "https://ORG@dev.azure.com/ORG/My-Project/_git/repo", + false, + ], + { + protocols: ["https"], + protocol: "https", + port: "", + resource: "dev.azure.com", + host: "dev.azure.com", + user: "ORG", + password: "", + pathname: "/ORG/My-Project/_git/repo", + hash: "", + search: "", + query: {}, + parse_failed: false, + }, + ], ]; tester.describe("check urls", test => {