Last active
October 27, 2015 20:24
-
-
Save michaelhidalgo/52be95e1c87ba20646b9 to your computer and use it in GitHub Desktop.
OpenRedirects
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
static void Main(string[] args) | |
{ | |
var url = "https://www.gogole.com"; | |
var result = url.IsLocalUrl(); | |
Console.WriteLine(result); | |
Console.ReadKey(); | |
} | |
public static bool IsLocalUrl(this string url) | |
{ | |
return !url.IsEmpty() && | |
((url[0] == '/' && (url.Length == 1 || | |
(url[1] != '/' && url[1] != '\\'))) || // "/" or "/foo" but not "//" or "/\" | |
(url.Length > 1 && | |
url[0] == '~' && url[1] == '/')); // "~/" or "~/foo" | |
} | |
public static bool IsEmpty(this string value) { | |
return string.IsNullOrEmpty(value); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment