function extractProtocol(address, location) {
  address = trimLeft(address);
  location = location || {};

  var match = protocolre.exec(address);
  var protocol = match[1] ? match[1].toLowerCase() : '';
  var rest = match[2] ? match[2] + match[3] : match[3];
  var slashes = !!(match[2] && match[2].length >= 2);

  if (protocol === 'file:') {
    if (slashes) {
      rest = rest.slice(2);
    }
  } else if (isSpecial(protocol)) {
    rest = match[3];
  } else if (protocol) {
    if (rest.indexOf('//') === 0) {
      rest = rest.slice(2);
    }
  } else if (slashes && location.hostname) {
    rest = match[3];
  }

  return {
    protocol: protocol,
    slashes: slashes,
    rest: rest
  };
}
A web application accepts a user-controlled input that specifies a link to an external site, and uses that link in a Redirect. This simplifies phishing attacks.