Last active
May 18, 2019 18:30
-
-
Save mhamri/85062325f7eb3125ed4184fa5b75b223 to your computer and use it in GitHub Desktop.
find any invalid character in the PATH environment variable
This file contains 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
using System; | |
using System.Collections; | |
using System.Linq; | |
using System.Linq.Expressions; | |
using System.Collections.Generic; | |
using System.Text; | |
namespace FindInvalidCharacterInEnvironment | |
{ | |
class Program | |
{ | |
static void Main(string[] args) | |
{ | |
var invalidCharacter= new HashSet<char>{ | |
'\"', '<', '>', '|', '\0', | |
(char)1, (char)2, (char)3, (char)4, (char)5, (char)6, (char)7, (char)8, (char)9, (char)10, | |
(char)11, (char)12, (char)13, (char)14, (char)15, (char)16, (char)17, (char)18, (char)19, (char)20, | |
(char)21, (char)22, (char)23, (char)24, (char)25, (char)26, (char)27, (char)28, (char)29, (char)30, | |
(char)31 | |
}; | |
var r = Environment.GetEnvironmentVariable("PATH").Split(';').Where(s=> s.Any(c=> invalidCharacter.Contains(c))).First(); | |
Console.WriteLine(r); | |
Console.WriteLine(BitConverter.ToString(Encoding.Unicode.GetBytes(r)).Replace("-"," ")); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment