Skip to content

Commit 26b4719

Browse files
committed
Merge branch 'monilpatel/ado-ssh-fix' of github.com:monil-patel/parse-url into new-version
2 parents eb3dc5f + fef96bb commit 26b4719

File tree

5 files changed

+142
-15
lines changed

5 files changed

+142
-15
lines changed

dist/index.js

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -288,8 +288,7 @@ function normalizeUrl(urlString, options) {
288288
const parseUrl = (url, normalize = false) => {
289289

290290
// Constants
291-
const GIT_RE = /^(?:([a-z_][a-z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/;
292-
291+
const GIT_RE = /^(?:([a-z_][a-z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:](([\~,\.\w,\-,\_,\/,\s]|%[0-9A-Fa-f]{2})+?(?:\.git|\/)?)$/;
293292
const throwErr = msg => {
294293
const err = new Error(msg);
295294
err.subject_url = url;

dist/index.mjs

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -282,8 +282,7 @@ function normalizeUrl(urlString, options) {
282282
const parseUrl = (url, normalize = false) => {
283283

284284
// Constants
285-
const GIT_RE = /^(?:([a-z_][a-z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/;
286-
285+
const GIT_RE = /^(?:([a-z_][a-z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:](([\~,\.\w,\-,\_,\/,\s]|%[0-9A-Fa-f]{2})+?(?:\.git|\/)?)$/;
287286
const throwErr = msg => {
288287
const err = new Error(msg);
289288
err.subject_url = url;

package.json

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,12 +6,14 @@
66
"module": "./dist/index.mjs",
77
"types": "./index.d.ts",
88
"exports": {
9-
"types": {
10-
"require": "./index.d.ts",
11-
"import": "./index.d.mts"
9+
"require": {
10+
"types": "./index.d.ts",
11+
"default": "./dist/index.js"
1212
},
13-
"require": "./dist/index.js",
14-
"import": "./dist/index.mjs"
13+
"import": {
14+
"types": "./index.d.mts",
15+
"default": "./dist/index.mjs"
16+
}
1517
},
1618
"directories": {
1719
"example": "example",

src/index.js

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
// Dependencies
2-
import parsePath from "parse-path";
2+
33
import normalizeUrl from "normalize-url";
4+
import parsePath from "parse-path";
45

56
/**
67
* parseUrl
@@ -36,8 +37,13 @@ import normalizeUrl from "normalize-url";
3637
const parseUrl = (url, normalize = false) => {
3738

3839
// Constants
39-
const GIT_RE = /^(?:([a-z_][a-z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:]([\~,\.\w,\-,\_,\/]+?(?:\.git|\/)?)$/
40-
40+
/**
41+
* ([a-z_][a-z0-9_-]{0,31}) Try to match the user
42+
* ([\w\.\-@]+) Match the host/resource
43+
* (([\~,\.\w,\-,\_,\/,\s]|%[0-9A-Fa-f]{2})+?(?:\.git|\/)?) Match the path, allowing spaces/white
44+
*/
45+
const GIT_RE = /^(?:([a-z_][a-z0-9_-]{0,31})@|https?:\/\/)([\w\.\-@]+)[\/:](([\~,\.\w,\-,\_,\/,\s]|%[0-9A-Fa-f]{2})+?(?:\.git|\/)?)$/;
46+
4147
const throwErr = msg => {
4248
const err = new Error(msg)
4349
err.subject_url = url
@@ -85,4 +91,4 @@ const parseUrl = (url, normalize = false) => {
8591

8692
parseUrl.MAX_INPUT_LENGTH = 2048
8793

88-
export default parseUrl;
94+
export default parseUrl;

test/index.mjs

Lines changed: 123 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
// Dependencies
2+
3+
import normalizeUrl from "normalize-url";
24
import parseUrl from "../dist/index.js";
35
import tester from "tester";
4-
import normalizeUrl from "normalize-url";
56

67
const INPUTS = [
78
[
@@ -165,7 +166,127 @@ const INPUTS = [
165166
, query: {}
166167
, parse_failed: false
167168
}
168-
]
169+
],
170+
[
171+
[
172+
"git@ssh.dev.azure.com:v3/ORG/My-Project/repo",
173+
false,
174+
],
175+
{
176+
protocols: ["ssh"],
177+
protocol: "ssh",
178+
port: "",
179+
resource: "ssh.dev.azure.com",
180+
host: "ssh.dev.azure.com",
181+
user: "git",
182+
password: "",
183+
pathname: "/v3/ORG/My-Project/repo",
184+
hash: "",
185+
search: "",
186+
query: {},
187+
parse_failed: false,
188+
},
189+
],
190+
[
191+
[
192+
"git@ssh.dev.azure.com:v3/ORG/My%20Project/repo",
193+
false,
194+
],
195+
{
196+
protocols: ["ssh"],
197+
protocol: "ssh",
198+
port: "",
199+
resource: "ssh.dev.azure.com",
200+
host: "ssh.dev.azure.com",
201+
user: "git",
202+
password: "",
203+
pathname: "/v3/ORG/My%20Project/repo",
204+
hash: "",
205+
search: "",
206+
query: {},
207+
parse_failed: false,
208+
},
209+
],
210+
[
211+
[
212+
"git@ssh.dev.azure.com:v3/ORG/My Project/repo",
213+
false,
214+
],
215+
{
216+
protocols: ["ssh"],
217+
protocol: "ssh",
218+
port: "",
219+
resource: "ssh.dev.azure.com",
220+
host: "ssh.dev.azure.com",
221+
user: "git",
222+
password: "",
223+
pathname: "/v3/ORG/My Project/repo",
224+
hash: "",
225+
search: "",
226+
query: {},
227+
parse_failed: false,
228+
},
229+
],
230+
[
231+
[
232+
"git@ssh.dev.azure.com:v3/ORG/My-Project/repo",
233+
false,
234+
],
235+
{
236+
protocols: ["ssh"],
237+
protocol: "ssh",
238+
port: "",
239+
resource: "ssh.dev.azure.com",
240+
host: "ssh.dev.azure.com",
241+
user: "git",
242+
password: "",
243+
pathname: "/v3/ORG/My-Project/repo",
244+
hash: "",
245+
search: "",
246+
query: {},
247+
parse_failed: false,
248+
},
249+
],
250+
[
251+
[
252+
"https://ORG@dev.azure.com/ORG/My%20Project/_git/repo",
253+
false,
254+
],
255+
{
256+
protocols: ["https"],
257+
protocol: "https",
258+
port: "",
259+
resource: "dev.azure.com",
260+
host: "dev.azure.com",
261+
user: "ORG",
262+
password: "",
263+
pathname: "/ORG/My%20Project/_git/repo",
264+
hash: "",
265+
search: "",
266+
query: {},
267+
parse_failed: false,
268+
},
269+
],
270+
[
271+
[
272+
"https://ORG@dev.azure.com/ORG/My-Project/_git/repo",
273+
false,
274+
],
275+
{
276+
protocols: ["https"],
277+
protocol: "https",
278+
port: "",
279+
resource: "dev.azure.com",
280+
host: "dev.azure.com",
281+
user: "ORG",
282+
password: "",
283+
pathname: "/ORG/My-Project/_git/repo",
284+
hash: "",
285+
search: "",
286+
query: {},
287+
parse_failed: false,
288+
},
289+
],
169290
];
170291

171292
tester.describe("check urls", test => {

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy