From cf5d98a8cadff87a54ffbf3fc55dbff4b12831bc Mon Sep 17 00:00:00 2001 From: Johan Liesén Date: Thu, 6 Sep 2012 10:35:53 +0200 Subject: Move instant tests to the top of the function: return early if possible --- lib/utils.coffee | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/lib/utils.coffee b/lib/utils.coffee index 00dce5b4..49481445 100644 --- a/lib/utils.coffee +++ b/lib/utils.coffee @@ -45,6 +45,12 @@ Utils = # Tries to detect if :str is a valid URL. isUrl: (str) -> + # Starts with a scheme: URL + return true if /^[a-z]{3,}:\/\//.test str + + # Must not contain spaces + return false if ' ' in str + # More or less RFC compliant URL host part parsing. This should be sufficient for our needs urlRegex = new RegExp( '^(?:([^:]+)(?::([^:]+))?@)?' + # user:password (optional) => \1, \2 @@ -57,12 +63,6 @@ Utils = specialHostNames = ['localhost'] - # Starts with a scheme: URL - return true if /^[a-z]{3,}:\/\//.test str - - # Must not contain spaces - return false if ' ' in str - # Try to parse the URL into its meaningful parts. If matching fails we're pretty sure that we don't have # some kind of URL here. match = urlRegex.exec (str.split '/')[0] -- cgit v1.2.3