Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update GIT_RE regex to match on SSH urls with spaces in Project/Repo Names #75

Merged
merged 3 commits into from
Jan 2, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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 @@ -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
Expand Down Expand Up @@ -84,4 +90,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