From 924cfd1d1cd473b773a6d43a6537f877338d9f99 Mon Sep 17 00:00:00 2001 From: wang_yue111 <648774160@qq.com> Date: Mon, 29 Mar 2021 16:02:39 +0800 Subject: [PATCH] fix: simplify the regular expression for shortcut matching PR-URL: https://github.com/npm/hosted-git-info/pull/76 Credit: @nlf Close: #76 Reviewed-by: @isaacs --- index.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/index.js b/index.js index 7f5ad1a..722dd1d 100644 --- a/index.js +++ b/index.js @@ -29,7 +29,7 @@ module.exports.fromUrl = function (giturl) { isGitHubShorthand(giturl) ? 'github:' + giturl : giturl ) var parsed = parseGitUrl(url) - var shortcutMatch = url.match(new RegExp('^([^:]+):(?:(?:[^@:]+(?:[^@]+)?@)?([^/]*))[/](.+?)(?:[.]git)?($|#)')) + var shortcutMatch = url.match(/^([^:]+):(?:[^@]+@)?(?:([^/]*)\/)?([^#]+)/) var matches = Object.keys(gitHosts).map(function (gitHostName) { var gitHostInfo = gitHosts[gitHostName] var auth = null @@ -42,7 +42,7 @@ module.exports.fromUrl = function (giturl) { var defaultRepresentation = null if (shortcutMatch && shortcutMatch[1] === gitHostName) { user = shortcutMatch[2] && decodeURIComponent(shortcutMatch[2]) - project = decodeURIComponent(shortcutMatch[3]) + project = decodeURIComponent(shortcutMatch[3].replace(/\.git$/, '')) defaultRepresentation = 'shortcut' } else { if (parsed.host !== gitHostInfo.domain) return -- 2.23.0