Last active
August 11, 2016 10:42
-
-
Save labilbe/a46b18625c8c7591008023320652b300 to your computer and use it in GitHub Desktop.
Checks if an incoming string is HTML encoded
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.Web; | |
// add strings here to check if they are URL encoded | |
var incomingStrings = new[] { | |
"not encoded", | |
"encodéd", | |
"dslkfjqmsdlkfjsdmfl", | |
"AbIfZVn4y514sJbt%2BCCMJy6lsmsMi6uOWyhUhynDSf1MEqZ%2FWJnwUuCFO8zMFa4jCRWQrXHKdBaHd9CCdDNfoKDnPg1W9No16JQbL2DBEGg%3D" | |
}; | |
foreach (var incomingString in incomingStrings) | |
{ | |
Console.WriteLine($"Is string '{incomingString}' URL encoded? {IsUrlEncoded(incomingString)}"); | |
} | |
private bool IsUrlEncoded(string source) | |
{ | |
return source != HttpUtility.UrlDecode(source); | |
} |
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
<?xml version="1.0" encoding="utf-8"?> | |
<packages> | |
<package id="ServiceStack.Text" version="4.0.62" targetFramework="net45" /> | |
<package id="ServiceStack.Client" version="4.0.62" targetFramework="net45" /> | |
<package id="ServiceStack.Interfaces" version="4.0.62" targetFramework="net45" /> | |
</packages> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment