Created
March 4, 2014 08:53
-
-
Save indexzero/9342685 to your computer and use it in GitHub Desktop.
Simple and safe URL parsing which allows for some special characters.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode 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