Skip to content

Instantly share code, notes, and snippets.

@indexzero
Created March 4, 2014 08:53
Show Gist options
  • Select an option

  • Save indexzero/9342685 to your computer and use it in GitHub Desktop.

Select an option

Save indexzero/9342685 to your computer and use it in GitHub Desktop.
Simple and safe URL parsing which allows for some special characters.
function safeParse (str) {
var whack = str.indexOf('://'),
at = str.lastIndexOf('@'),
auth;
str = str.replace(/\/$/, '');
auth = str.substring(whack + 3, at);
return {
url: str.replace(auth + '@', ''),
auth: auth
};
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment