Skip to content

Commit

Permalink
Merge branch 'support-custom-user' of github.com:privatenumber/parse-…
Browse files Browse the repository at this point in the history
…url into new-version
  • Loading branch information
IonicaBizau committed Aug 30, 2022
2 parents 0baab4f + 9500430 commit 778a0a5
Show file tree
Hide file tree
Showing 4 changed files with 32 additions and 15 deletions.
10 changes: 5 additions & 5 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -288,7 +288,7 @@ function normalizeUrl(urlString, options) {
const parseUrl = (url, normalize = false) => {

// Constants
const GIT_RE = /^(?:git@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/;
const GIT_RE = /^(?:([a-z_][a-z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/;

const throwErr = msg => {
const err = new Error(msg);
Expand Down Expand Up @@ -322,10 +322,10 @@ const parseUrl = (url, normalize = false) => {
if (matched) {
parsed.protocols = ["ssh"];
parsed.protocol = "ssh";
parsed.resource = matched[1];
parsed.host = matched[1];
parsed.user = "git";
parsed.pathname = `/${matched[2]}`;
parsed.resource = matched[2];
parsed.host = matched[2];
parsed.user = matched[1];
parsed.pathname = `/${matched[3]}`;
parsed.parse_failed = false;
} else {
throwErr("URL parsing failed.");
Expand Down
10 changes: 5 additions & 5 deletions dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ function normalizeUrl(urlString, options) {
const parseUrl = (url, normalize = false) => {

// Constants
const GIT_RE = /^(?:git@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/;
const GIT_RE = /^(?:([a-z_][a-z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/;

const throwErr = msg => {
const err = new Error(msg);
Expand Down Expand Up @@ -316,10 +316,10 @@ const parseUrl = (url, normalize = false) => {
if (matched) {
parsed.protocols = ["ssh"];
parsed.protocol = "ssh";
parsed.resource = matched[1];
parsed.host = matched[1];
parsed.user = "git";
parsed.pathname = `/${matched[2]}`;
parsed.resource = matched[2];
parsed.host = matched[2];
parsed.user = matched[1];
parsed.pathname = `/${matched[3]}`;
parsed.parse_failed = false;
} else {
throwErr("URL parsing failed.");
Expand Down
10 changes: 5 additions & 5 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ import normalizeUrl from "normalize-url";
const parseUrl = (url, normalize = false) => {

// Constants
const GIT_RE = /^(?:git@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/
const GIT_RE = /^(?:([a-z_][a-z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/

const throwErr = msg => {
const err = new Error(msg)
Expand Down Expand Up @@ -69,10 +69,10 @@ const parseUrl = (url, normalize = false) => {
if (matched) {
parsed.protocols = ["ssh"]
parsed.protocol = "ssh"
parsed.resource = matched[1]
parsed.host = matched[1]
parsed.user = "git"
parsed.pathname = `/${matched[2]}`
parsed.resource = matched[2]
parsed.host = matched[2]
parsed.user = matched[1]
parsed.pathname = `/${matched[3]}`
parsed.parse_failed = false
} else {
throwErr("URL parsing failed.")
Expand Down
17 changes: 17 additions & 0 deletions test/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,23 @@ const INPUTS = [
, parse_failed: false
}
]
, [
["[email protected]:my-org/my-repo.git", false],
{
protocols: [ 'ssh' ]
, protocol: 'ssh'
, port: ''
, resource: 'github.my-enterprise.com'
, host: 'github.my-enterprise.com'
, user: 'org-12345678'
, password: ''
, pathname: '/my-org/my-repo.git'
, hash: ''
, search: ''
, query: {}
, parse_failed: false
}
]
, [
["[email protected]:halup/Cloud.API.Gateway.git", false]
, {
Expand Down

0 comments on commit 778a0a5

Please sign in to comment.