<commit_before>module.exports = urlParse;

function urlParse(url) {
  var protocol, user, pass, hostname, port, pathname, query;
  var match, host, path;
  if (match = url.match(/^(?:(wss?|https?|git|ssh):\/\/)([^\/]+)([^:]+)$/)) {
    protocol = match[1],
    host = match[2];
    path = match[3];
  }
  else if (match = url.match(/^(?:([^@]+)@)?([^:\/]+)([:\/][^:\/][^:]+)$/)) {
    protocol = "ssh";
    user = match[1];
    hostname = match[2];
    pathname = match[3];
  }
  else {
    throw new Error("Uknown URL format: " + url);
  }
  if (host) {
    match = host.match(/^(?:([^@:]+)(?::([^@]+))?@)?([^@:]+)(?::([0-9]+))?$/);
    user = match[1];
    pass = match[2];
    hostname = match[3];
    port = match[4];
  }
  if (path) {
    match = path.match(/^([^?]+)(?:\?(.*))?$/);
    pathname = match[1];
    query = match[2];
  }

  if (port) port = parseInt(port, 10);
  else if (protocol === "http" || protocol === "ws") port = 80;
  else if (protocol === "https" || protocol === "wss") port = 443;
  else if (protocol === "ssh") port = 22;
  else if (protocol === "git") port = 9418;

  var opt = {
    protocol: protocol
  };
  if (user) opt.user = user;<commit_msg>Clean up ssh url handling<commit_after>module.exports = urlParse;

function urlParse(url) {
  var protocol, user, pass, hostname, port, pathname, query;
  var match, host, path;
  // Match URL style remotes
  if (match = url.match(/^(?:(wss?|https?|git|ssh):\/\/)([^\/]+)([^:]+)$/)) {
    protocol = match[1],
    host = match[2];
    path = match[3];
    match = host.match(/^(?:([^@:]+)(?::([^@]+))?@)?([^@:]+)(?::([0-9]+))?$/);
    user = match[1];
    pass = match[2];
    hostname = match[3];
    port = match[4];
    match = path.match(/^([^?]+)(?:\?(.*))?$/);
    pathname = match[1];
    if (protocol === "ssh") pathname = pathname.substr(1);
    query = match[2];
  }
  // Match scp style ssh remotes
  else if (match = url.match(/^(?:([^@]+)@)?([^:\/]+)([:\/][^:\/][^:]+)$/)) {
    protocol = "ssh";
    user = match[1];
    hostname = match[2];
    pathname = match[3];
    if (pathname[0] === ":") pathname = pathname.substr(1);
  }
  else {
    throw new Error("Uknown URL format: " + url);
  }

  if (port) port = parseInt(port, 10);
  else if (protocol === "http" || protocol === "ws") port = 80;
  else if (protocol === "https" || protocol === "wss") port = 443;
  else if (protocol === "ssh") port = 22;
  else if (protocol === "git") port = 9418;

  var opt = {
    url: url,
    protocol: protocol
  };
  if (user) opt.user = user;
{'fraction_non_alphanumeric': 0.27323052589956504, 'fraction_numerical': 0.022538552787663108, 'mean_word_length': 3.067524115755627, 'pattern_counts': {'":': 1, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '716569', 'n_tokens_mistral': 1017, 'n_tokens_neox': 966, 'n_words': 229}