Skip to content

Commit

Permalink
Merge branch 'monilpatel/ado-ssh-fix' of github.com:monil-patel/parse…
Browse files Browse the repository at this point in the history
…-url into new-version
  • Loading branch information
IonicaBizau committed Jan 2, 2024
2 parents eb3dc5f + fef96bb commit 26b4719
Show file tree
Hide file tree
Showing 5 changed files with 142 additions and 15 deletions.
3 changes: 1 addition & 2 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
3 changes: 1 addition & 2 deletions dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
14 changes: 10 additions & 4 deletions src/index.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
// Dependencies
import parsePath from "parse-path";

import normalizeUrl from "normalize-url";
import parsePath from "parse-path";

/**
* parseUrl
Expand Down Expand Up @@ -36,8 +37,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
Expand Down Expand Up @@ -85,4 +91,4 @@ const parseUrl = (url, normalize = false) => {

parseUrl.MAX_INPUT_LENGTH = 2048

export default parseUrl;
export default parseUrl;
125 changes: 123 additions & 2 deletions test/index.mjs
Original file line number Diff line number Diff line change
@@ -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 = [
[
Expand Down Expand Up @@ -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 => {
Expand Down

0 comments on commit 26b4719

Please sign in to comment.