Skip to content

Commit

Permalink
revert accidently prettier changes from vscode
Browse files Browse the repository at this point in the history
  • Loading branch information
monil-patel committed Nov 21, 2023
1 parent 12c6124 commit 0175389
Show file tree
Hide file tree
Showing 4 changed files with 125 additions and 146 deletions.
89 changes: 43 additions & 46 deletions dist/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -286,55 +286,52 @@ function normalizeUrl(urlString, options) {
* - `parse_failed` (Boolean): Whether the parsing failed or not.
*/
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;
throw err;
};

if (typeof url !== "string" || !url.trim()) {
throwErr("Invalid url.");
}

if (url.length > parseUrl.MAX_INPUT_LENGTH) {
throwErr(
"Input exceeds maximum length. If needed, change the value of parseUrl.MAX_INPUT_LENGTH."
);
}

if (normalize) {
if (typeof normalize !== "object") {
normalize = {
stripHash: false,
};

// Constants
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;
throw err
};

if (typeof url !== "string" || !url.trim()) {
throwErr("Invalid url.");
}

if (url.length > parseUrl.MAX_INPUT_LENGTH) {
throwErr("Input exceeds maximum length. If needed, change the value of parseUrl.MAX_INPUT_LENGTH.");
}
url = normalizeUrl(url, normalize);
}

const parsed = parsePath__default["default"](url);

// Potential git-ssh urls
if (parsed.parse_failed) {
const matched = parsed.href.match(GIT_RE);

if (matched) {
parsed.protocols = ["ssh"];
parsed.protocol = "ssh";
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.");

if (normalize) {
if (typeof normalize !== "object") {
normalize = {
stripHash: false
};
}
url = normalizeUrl(url, normalize);
}

const parsed = parsePath__default["default"](url);

// Potential git-ssh urls
if (parsed.parse_failed) {
const matched = parsed.href.match(GIT_RE);

if (matched) {
parsed.protocols = ["ssh"];
parsed.protocol = "ssh";
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.");
}
}
}

return parsed;
return parsed;
};

parseUrl.MAX_INPUT_LENGTH = 2048;
Expand Down
89 changes: 43 additions & 46 deletions dist/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -280,55 +280,52 @@ function normalizeUrl(urlString, options) {
* - `parse_failed` (Boolean): Whether the parsing failed or not.
*/
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;
throw err;
};

if (typeof url !== "string" || !url.trim()) {
throwErr("Invalid url.");
}

if (url.length > parseUrl.MAX_INPUT_LENGTH) {
throwErr(
"Input exceeds maximum length. If needed, change the value of parseUrl.MAX_INPUT_LENGTH."
);
}

if (normalize) {
if (typeof normalize !== "object") {
normalize = {
stripHash: false,
};

// Constants
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;
throw err
};

if (typeof url !== "string" || !url.trim()) {
throwErr("Invalid url.");
}

if (url.length > parseUrl.MAX_INPUT_LENGTH) {
throwErr("Input exceeds maximum length. If needed, change the value of parseUrl.MAX_INPUT_LENGTH.");
}
url = normalizeUrl(url, normalize);
}

const parsed = parsePath(url);

// Potential git-ssh urls
if (parsed.parse_failed) {
const matched = parsed.href.match(GIT_RE);

if (matched) {
parsed.protocols = ["ssh"];
parsed.protocol = "ssh";
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.");

if (normalize) {
if (typeof normalize !== "object") {
normalize = {
stripHash: false
};
}
url = normalizeUrl(url, normalize);
}

const parsed = parsePath(url);

// Potential git-ssh urls
if (parsed.parse_failed) {
const matched = parsed.href.match(GIT_RE);

if (matched) {
parsed.protocols = ["ssh"];
parsed.protocol = "ssh";
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.");
}
}
}

return parsed;
return parsed;
};

parseUrl.MAX_INPUT_LENGTH = 2048;
Expand Down
81 changes: 39 additions & 42 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,57 +34,54 @@ import parsePath from "parse-path";
* - `parse_failed` (Boolean): Whether the parsing failed or not.
*/
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;
throw err;
};

if (typeof url !== "string" || !url.trim()) {
throwErr("Invalid url.");
}
// Constants
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
throw err
}

if (typeof url !== "string" || !url.trim()) {
throwErr("Invalid url.")
}

if (url.length > parseUrl.MAX_INPUT_LENGTH) {
throwErr(
"Input exceeds maximum length. If needed, change the value of parseUrl.MAX_INPUT_LENGTH."
);
}
if (url.length > parseUrl.MAX_INPUT_LENGTH) {
throwErr("Input exceeds maximum length. If needed, change the value of parseUrl.MAX_INPUT_LENGTH.")
}

if (normalize) {
if (typeof normalize !== "object") {
normalize = {
stripHash: false,
};
if (normalize) {
if (typeof normalize !== "object") {
normalize = {
stripHash: false
}
}
url = normalizeUrl(url, normalize)
}
url = normalizeUrl(url, normalize);
}

const parsed = parsePath(url);
const parsed = parsePath(url)

// Potential git-ssh urls
if (parsed.parse_failed) {
const matched = parsed.href.match(GIT_RE);
// Potential git-ssh urls
if (parsed.parse_failed) {
const matched = parsed.href.match(GIT_RE)

if (matched) {
parsed.protocols = ["ssh"];
parsed.protocol = "ssh";
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.");
if (matched) {
parsed.protocols = ["ssh"]
parsed.protocol = "ssh"
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.")
}
}
}

return parsed;
};
return parsed;
}

parseUrl.MAX_INPUT_LENGTH = 2048

export default parseUrl;
export default parseUrl;
12 changes: 0 additions & 12 deletions test/index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -289,18 +289,6 @@ const INPUTS = [
],
];





// test('SSH URL with URL-encoded spaces', 'git@ssh.dev.azure.com:v3/ORG/My%20project/repo');
// test('SSH URL with non URL-encoded spaces', 'git@ssh.dev.azure.com:v3/ORG/My project/repo');
// test('SSH URL without spaces', 'git@ssh.dev.azure.com:v3/ORG/My-project/repo');
// test('HTTPS URL with URL-encoded spaces', 'https://ORG@dev.azure.com/ORG/My%20project/_git/repo');
// test('HTTPS URL with non URL-encoded spaces', 'https://ORG@dev.azure.com/ORG/My project/_git/repo');
// test('HTTPS URL without spaces', 'https://ORG@dev.azure.com/ORG/My-project/_git/repo');


tester.describe("check urls", test => {
INPUTS.forEach(function (c) {
let url = Array.isArray(c[0]) ? c[0][0] : c[0]
Expand Down

0 comments on commit 0175389

Please sign in to comment.